[][src]Trait failure_ext::OptionExt

pub trait OptionExt<T> {
    fn ok_or_context<D>(self, context: D) -> Result<T, Context<D>>
    where
        D: Display + Send + Sync + 'static
; }

Extension methods for Option.

Required methods

fn ok_or_context<D>(self, context: D) -> Result<T, Context<D>> where
    D: Display + Send + Sync + 'static, 

Wraps the error type in a context type.

Examples

let opt: Option<String> = None;
let x = opt.ok_or_context(format!("An error occured")).unwrap_err();

let x = format!("{}", x);

assert_eq!(x, "An error occured");
Loading content...

Implementations on Foreign Types

impl<T> OptionExt<T> for Option<T>[src]

Loading content...

Implementors

Loading content...