Struct Option
pub struct Option<T>
{ /* private fields */ }
Implementations
impl<T> Option<T>
pub fn none() -> Self
pub fn some(_value: T) -> Self
Constructs a Some wrapper around the given value
pub fn is_none(self) -> bool
True if this Option is None
pub fn is_some(self) -> bool
True if this Option is Some
pub fn unwrap(self) -> T
Asserts self.is_some() and returns the wrapped value.
pub fn unwrap_unchecked(self) -> T
Returns the inner value without asserting self.is_some()
Note that if self is None, there is no guarantee what value will be returned,
only that it will be of type T.
pub fn unwrap_or(self, default: T) -> T
Returns the wrapped value if self.is_some(). Otherwise, returns the given default value.
pub fn unwrap_or_else<Env>(self, default: fn[Env]() -> T) -> T
Returns the wrapped value if self.is_some(). Otherwise, calls the given function to return
a default value.
pub fn expect<let N: u32, MessageTypes>(
self,
message: fmtstr<N, MessageTypes>,
) -> T
Asserts self.is_some() with a provided custom message and returns the contained Some value
pub fn map<U, Env>(self, f: fn[Env](T) -> U) -> Option<U>
If self is Some(x), this returns Some(f(x)). Otherwise, this returns None.
pub fn map_or<U, Env>(self, default: U, f: fn[Env](T) -> U) -> U
If self is Some(x), this returns f(x). Otherwise, this returns the given default value.
pub fn map_or_else<U, Env1, Env2>(
self,
default: fn[Env1]() -> U,
f: fn[Env2](T) -> U,
) -> U
If self is Some(x), this returns f(x). Otherwise, this returns default().
pub fn and(self, other: Self) -> Self
Returns None if self is None. Otherwise, this returns other.
pub fn and_then<U, Env>(self, f: fn[Env](T) -> Option<U>) -> Option<U>
If self is None, this returns None. Otherwise, this calls the given function with the Some value contained within self, and returns the result of that call.
In some languages this function is called flat_map or bind.
pub fn or(self, other: Self) -> Self
If self is Some, return self. Otherwise, return other.
pub fn or_else<Env>(self, default: fn[Env]() -> Self) -> Self
If self is Some, return self. Otherwise, return default().
pub fn xor(self, other: Self) -> Self
pub fn filter<Env>(self, predicate: fn[Env](T) -> bool) -> Self
Returns Some(x) if self is Some(x) and predicate(x) is true.
Otherwise, this returns None
pub fn flatten(option: Option<Self>) -> Self
Flattens an Option<Option<T>> into a Option<T>. This returns None if the outer Option is None. Otherwise, this returns the inner Option.
Trait implementations
impl<T> Default for Option<T>
pub fn default() -> Self
impl<T> Eq for Option<T>
where
T: Eq
pub fn eq(self, other: Self) -> bool
impl<T> Hash for Option<T>
where
T: Hash
pub fn hash<H>(self, state: &mut H)
where
H: Hasher
impl<T> Ord for Option<T>
where
T: Ord
pub fn cmp(self, other: Self) -> Ordering
Constructs a None value