[−][src]Trait err_or::OptionExt
Extension trait for Option
.
Associated Types
Loading content...Required methods
pub fn err_or<O>(self, ok: O) -> Result<O, Self::Item>
[src]
Transforms the Option<T>
into a Result<O, T>
, mapping Some(v)
to Err(v)
and None
to Ok(ok)
.
Arguments passed to err_or
are eagerly evaluated; if you are passing
the result of a function call, it is recommended to use
err_or_else
, which is lazily evaluated.
Examples
use err_or::OptionExt; let x = Some("foo"); assert_eq!(x.err_or(0), Err("foo")); let x: Option<&str> = None; assert_eq!(x.err_or(0), Ok(0));
pub fn err_or_else<O, F>(self, ok: F) -> Result<O, Self::Item> where
F: FnOnce() -> O,
[src]
F: FnOnce() -> O,
Implementations on Foreign Types
impl<T> OptionExt for Option<T>
[src]
type Item = T
pub fn err_or<O>(self, ok: O) -> Result<O, Self::Item>
[src]
pub fn err_or_else<O, F>(self, ok: F) -> Result<O, Self::Item> where
F: FnOnce() -> O,
[src]
F: FnOnce() -> O,