Skip to main content

ErrorExt

Trait ErrorExt 

pub trait ErrorExt: SealedErrorExt {
Show 17 methods // Required methods fn into_box_error(self) -> Box<dyn Error + Send + Sync>; fn into_opaque_error(self) -> OpaqueError; fn context<M>(self, value: M) -> Box<dyn Error + Send + Sync> where M: Debug + Display + Send + Sync + 'static; fn context_hex<M>(self, value: M) -> Box<dyn Error + Send + Sync> where M: Debug + Send + Sync + 'static; fn context_debug<M>(self, value: M) -> Box<dyn Error + Send + Sync> where M: Debug + Send + Sync + 'static; fn context_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync> where M: Debug + Display + Send + Sync + 'static; fn context_str_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync> where M: Into<String>; fn context_hex_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync> where M: Debug + Send + Sync + 'static; fn context_debug_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync> where M: Debug + Send + Sync + 'static; fn with_context<C, F>(self, cb: F) -> Box<dyn Error + Send + Sync> where C: Debug + Display + Send + Sync + 'static, F: FnOnce() -> C; fn with_context_hex<C, F>(self, cb: F) -> Box<dyn Error + Send + Sync> where C: Debug + Send + Sync + 'static, F: FnOnce() -> C; fn with_context_debug<C, F>(self, cb: F) -> Box<dyn Error + Send + Sync> where C: Debug + Send + Sync + 'static, F: FnOnce() -> C; fn with_context_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync> where C: Debug + Display + Send + Sync + 'static, F: FnOnce() -> C; fn with_context_str_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync> where C: Into<String>, F: FnOnce() -> C; fn with_context_hex_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync> where C: Debug + Send + Sync + 'static, F: FnOnce() -> C; fn with_context_debug_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync> where C: Debug + Send + Sync + 'static, F: FnOnce() -> C; fn backtrace(self) -> Box<dyn Error + Send + Sync>;
}
Expand description

Extends the Error type with methods for working with errors.

See the module level documentation for more information.

Required Methods§

fn into_box_error(self) -> Box<dyn Error + Send + Sync>

Return self as BoxError without additional context.

fn into_opaque_error(self) -> OpaqueError

Return self as OpaqueError without additional context.

Pretty much always you’ll want Self::into_box_error instead, but OpaqueError can be useful as a last-resort, should you run into higher-rank lifetime issues while spawning (tokio) tasks…

fn context<M>(self, value: M) -> Box<dyn Error + Send + Sync>
where M: Debug + Display + Send + Sync + 'static,

Wrap the error in a context.

fn context_hex<M>(self, value: M) -> Box<dyn Error + Send + Sync>
where M: Debug + Send + Sync + 'static,

Wrap the error in a context, using fmt::LowerHex as fmt::Debug and [fmt::Display].

fn context_debug<M>(self, value: M) -> Box<dyn Error + Send + Sync>
where M: Debug + Send + Sync + 'static,

Wrap the error in a context, using fmt::Debug as [fmt::Display].

fn context_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync>
where M: Debug + Display + Send + Sync + 'static,

Wrap the error in a keyed context.

fn context_str_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync>
where M: Into<String>,

Same as Self::context_field but using a string-like value, this is useful in case you need to pass a string slice which is borrowed and thus cannot be passed as part of ’static error.

fn context_hex_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync>
where M: Debug + Send + Sync + 'static,

Wrap the error in a keyed context, using fmt::LowerHex as fmt::Debug and [fmt::Display].

fn context_debug_field<M>( self, key: &'static str, value: M, ) -> Box<dyn Error + Send + Sync>
where M: Debug + Send + Sync + 'static,

Wrap the error in a keyed context, using fmt::Debug as [fmt::Display].

fn with_context<C, F>(self, cb: F) -> Box<dyn Error + Send + Sync>
where C: Debug + Display + Send + Sync + 'static, F: FnOnce() -> C,

Lazily wrap the error with a context.

fn with_context_hex<C, F>(self, cb: F) -> Box<dyn Error + Send + Sync>
where C: Debug + Send + Sync + 'static, F: FnOnce() -> C,

Lazily wrap the error with a context, using fmt::LowerHex as fmt::Debug and [fmt::Display].

fn with_context_debug<C, F>(self, cb: F) -> Box<dyn Error + Send + Sync>
where C: Debug + Send + Sync + 'static, F: FnOnce() -> C,

Lazily wrap the error with a context, using fmt::Debug as [fmt::Display].

fn with_context_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync>
where C: Debug + Display + Send + Sync + 'static, F: FnOnce() -> C,

Lazily wrap the error with keyed context.

fn with_context_str_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync>
where C: Into<String>, F: FnOnce() -> C,

Same as Self::with_context_field but using a string-like value, this is useful in case you need to pass a string slice which is borrowed and thus cannot be passed as part of ’static error.

fn with_context_hex_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync>
where C: Debug + Send + Sync + 'static, F: FnOnce() -> C,

Lazily wrap the error with keyed context using fmt::LowerHex as fmt::Debug and [fmt::Display].

fn with_context_debug_field<C, F>( self, key: &'static str, cb: F, ) -> Box<dyn Error + Send + Sync>
where C: Debug + Send + Sync + 'static, F: FnOnce() -> C,

Lazily wrap the error with keyed context using fmt::Debug as [fmt::Display].

fn backtrace(self) -> Box<dyn Error + Send + Sync>

Add a Backtrace to the error.

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§

§

impl<Error> ErrorExt for Error
where Error: Into<Box<dyn Error + Send + Sync>>,