ConvertOption

Trait ConvertOption 

Source
pub trait ConvertOption<T>: Sized {
    // Required methods
    fn context<C>(self, context: C) -> Result<T, CtxError>
       where C: Into<Cow<'static, str>>;
    fn context_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
       where F: FnOnce() -> C,
             C: Into<Cow<'static, str>>;
    fn attach<C>(self, context: C) -> Result<T, CtxError>
       where C: AnyDebugSendSync + 'static;
    fn attach_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
       where F: FnOnce() -> C,
             C: AnyDebugSendSync + 'static;
    fn attach_override<C>(self, context: C) -> Result<T, CtxError>
       where C: AnyDebugSendSync + 'static;
    fn attach_override_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
       where F: FnOnce() -> C,
             C: AnyDebugSendSync + 'static;
}
Expand description

Helper on Options for conversion to our Results.

Required Methods§

Source

fn context<C>(self, context: C) -> Result<T, CtxError>
where C: Into<Cow<'static, str>>,

Convert None to an error and add human context to the error.

Source

fn context_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
where F: FnOnce() -> C, C: Into<Cow<'static, str>>,

Convert None to an error and add human context to the error via a closure.

Source

fn attach<C>(self, context: C) -> Result<T, CtxError>
where C: AnyDebugSendSync + 'static,

Convert None to an error and add machine context to the error.

This will not override existing attachments. If you want to replace and override any existing attachments of the same type, use attach_override instead.

Source

fn attach_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
where F: FnOnce() -> C, C: AnyDebugSendSync + 'static,

Convert None to an error and add machine context to the error via a closure.

This will not override existing attachments. If you want to replace and override any existing attachments of the same type, use attach_override instead.

Source

fn attach_override<C>(self, context: C) -> Result<T, CtxError>
where C: AnyDebugSendSync + 'static,

Convert None to an error and set machine context in the error.

This will override existing attachments of the same type. If you want to add attachments of the same type, use attach instead.

Source

fn attach_override_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
where F: FnOnce() -> C, C: AnyDebugSendSync + 'static,

Convert None to an error and set machine context in the error via a closure.

This will override existing attachments of the same type. If you want to add attachments of the same type, use attach instead.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> ConvertOption<T> for Option<T>

Source§

fn context<C>(self, context: C) -> Result<T, CtxError>
where C: Into<Cow<'static, str>>,

Source§

fn context_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
where F: FnOnce() -> C, C: Into<Cow<'static, str>>,

Source§

fn attach<C>(self, context: C) -> Result<T, CtxError>
where C: AnyDebugSendSync + 'static,

Source§

fn attach_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
where F: FnOnce() -> C, C: AnyDebugSendSync + 'static,

Source§

fn attach_override<C>(self, context: C) -> Result<T, CtxError>
where C: AnyDebugSendSync + 'static,

Source§

fn attach_override_with<F, C>(self, context_fn: F) -> Result<T, CtxError>
where F: FnOnce() -> C, C: AnyDebugSendSync + 'static,

Implementors§