Module std::option

Option<T>'s methods. Option is the prelude's enum; its inherent methods are this module's, which every program loads, so o.is_none() needs no use. unwrap and expect are built-ins, not methods here; no method here can panic. The combinators take closures as std::iter's adapters do (F: Fn(T) -> U, std::fun): a closure literal there may borrow the enclosing locals, and its body runs with no capabilities, so these methods' rows are empty too. std::string prints an option as it is written, Some(3) or None.

Source: std/option.weir; committed interface: std/option.iface. Index

impl<T: linear> Option<T>

method is_some

pub fn is_some(&self) -> Bool

Whether there is a value.

method is_none

pub fn is_none(&self) -> Bool

Whether there is none.

method replace

pub fn replace(&mut self, v: T) -> Option<T>

Puts Some(v) in place and answers what was there.

method take

pub fn take(&mut self) -> Option<T>

Takes the value out, leaving None in place.

method as_ref

pub fn as_ref(&self) -> Option<&T>

A borrow of the value, if there is one.

method as_mut

pub fn as_mut(&mut self) -> Option<&mut T>

A mutable borrow of the value, if there is one.

impl<T> Option<T>

method map

pub fn map<U, F: Fn(T) -> U>(self, f: F) -> Option<U>

Some(f(x)) of the value x, else None; f runs only on Some.

method and_then

pub fn and_then<U, F: Fn(T) -> Option<U>>(self, f: F) -> Option<U>

f(x) of the value x, else None: f may itself answer None.

method or_else

pub fn or_else<F: Fn() -> Option<T>>(self, f: F) -> Option<T>

Itself if it holds a value, else what f makes; f runs only on None.

method unwrap_or_else

pub fn unwrap_or_else<F: Fn() -> T>(self, f: F) -> T

The value, else what f makes; f runs only on None.

method ok_or_else

pub fn ok_or_else<E, F: Fn() -> E>(self, f: F) -> Result<T, E>

Ok of the value, else Err of what f makes; f runs only on None.

method is_some_and

pub fn is_some_and<P: Fn(T) -> Bool>(self, p: P) -> Bool

Whether there is a value and p holds of it; p takes the value.

method unwrap_or

pub fn unwrap_or(self, d: T) -> T

The value, else d; d is evaluated by the caller either way.

method ok_or

pub fn ok_or<E>(self, e: E) -> Result<T, E>

Ok of the value, else Err(e).

method filter

pub fn filter<P: Fn(&T) -> Bool>(self, p: P) -> Option<T>

Itself if it holds a value p accepts, else None; a rejected value is dropped.