Skip to main content

OptionExt

Trait OptionExt 

Source
pub trait OptionExt {
    type Some;

    // Required methods
    fn ok_or_raise<A, F>(self, err: F) -> Result<Self::Some>
       where A: Error + Send + Sync + 'static,
             F: FnOnce() -> A;
    fn ok_or_raise_typed<A, F>(self, err: F) -> ExnResult<Self::Some, A>
       where A: Error + Send + Sync + 'static,
             F: FnOnce() -> A;
    fn ok_or_raise_erased<A, F>(self, err: F) -> ExnResult<Self::Some>
       where A: Error + Send + Sync + 'static,
             F: FnOnce() -> A;
}
Expand description

Raise errors lazily on Option::None.

Required Associated Types§

Source

type Some

The Some type.

Required Methods§

Source

fn ok_or_raise<A, F>(self, err: F) -> Result<Self::Some>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Raise err() on None, returning a public Result. Existing Error values are retained unchanged.

Source

fn ok_or_raise_typed<A, F>(self, err: F) -> ExnResult<Self::Some, A>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Construct a typed Exn on the None variant.

Source

fn ok_or_raise_erased<A, F>(self, err: F) -> ExnResult<Self::Some>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Construct a new Exn on the None variant, with type erasure. The generated error is raised with ErrorExt::raise_erased.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> OptionExt for Option<T>

Source§

type Some = T

Source§

fn ok_or_raise<A, F>(self, err: F) -> Result<T>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Source§

fn ok_or_raise_typed<A, F>(self, err: F) -> ExnResult<T, A>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Source§

fn ok_or_raise_erased<A, F>(self, err: F) -> ExnResult<T>
where A: Error + Send + Sync + 'static, F: FnOnce() -> A,

Implementors§