Trait ResultExt

Source
pub trait ResultExt<T, E>: Sized {
    // Required methods
    fn context_with<C: ToTokensError + 'static>(
        self,
        error: impl FnOnce() -> C,
    ) -> Result<T, Error>;
    fn attachment(self, label: &'static str, msg: impl Display) -> Self
       where E: Attachment;

    // Provided methods
    fn context(self, error: impl ToTokensError + 'static) -> Result<T, Error> { ... }
    fn error(self, msg: impl Display) -> Self
       where E: Attachment { ... }
    fn warning(self, msg: impl Display) -> Self
       where E: Attachment { ... }
    fn note(self, msg: impl Display) -> Self
       where E: Attachment { ... }
    fn help(self, msg: impl Display) -> Self
       where E: Attachment { ... }
}
Expand description

Required Methods§

Source

fn context_with<C: ToTokensError + 'static>( self, error: impl FnOnce() -> C, ) -> Result<T, Error>

If self is error, attaches another error, closure is only executed if the Result is Err

Source

fn attachment(self, label: &'static str, msg: impl Display) -> Self
where E: Attachment,

If self is error, extend error message

Only works if E implements Attachment which is the case for ErrorMessage

Provided Methods§

Source

fn context(self, error: impl ToTokensError + 'static) -> Result<T, Error>

If self is error, attaches another error

Source

fn error(self, msg: impl Display) -> Self
where E: Attachment,

Attaches a new error message to self reusing the same span

Source

fn warning(self, msg: impl Display) -> Self
where E: Attachment,

Attaches a new warning message to self reusing the same span

Source

fn note(self, msg: impl Display) -> Self
where E: Attachment,

Attaches a new note message to self reusing the same span

Source

fn help(self, msg: impl Display) -> Self
where E: Attachment,

Attaches a new help message to self reusing the same span

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.

Implementors§

Source§

impl<T, E: ToTokensError + 'static> ResultExt<T, E> for Result<T, E>