pub struct Error { /* private fields */ }
Expand description
An error type that extends anyhow::Error
with named fields.
Implementations§
Source§impl Error
impl Error
Sourcepub fn msg<T: Display + Debug + Send + Sync + 'static>(msg: T) -> Self
pub fn msg<T: Display + Debug + Send + Sync + 'static>(msg: T) -> Self
Create a new error with a message and optional fields.
Sourcepub fn with_field<V: Display>(self, key: &'static str, value: V) -> Self
pub fn with_field<V: Display>(self, key: &'static str, value: V) -> Self
Add a named field to this error.
Sourcepub fn with_field_debug<V: Debug>(self, key: &'static str, value: V) -> Self
pub fn with_field_debug<V: Debug>(self, key: &'static str, value: V) -> Self
Add a named field with debug formatting to this error.
Sourcepub fn get_field(&self, key: &str) -> Option<&str>
pub fn get_field(&self, key: &str) -> Option<&str>
Get a specific field value by key, this is an O(n) operation.
Sourcepub fn context<C: Display + Send + Sync + 'static>(self, context: C) -> Self
pub fn context<C: Display + Send + Sync + 'static>(self, context: C) -> Self
Add context to this error, see anyhow::Context
for more details.
Sourcepub fn with_context<C, F>(self, f: F) -> Self
pub fn with_context<C, F>(self, f: F) -> Self
Add context to this error with a closure, see anyhow::Context
for more details.
Sourcepub fn root_cause(&self) -> &dyn StdError
pub fn root_cause(&self) -> &dyn StdError
Get the root cause of this error.
Sourcepub fn downcast_ref<E>(&self) -> Option<&E>
pub fn downcast_ref<E>(&self) -> Option<&E>
Downcast the error to a reference to a concrete type.
Sourcepub fn downcast_mut<E>(&mut self) -> Option<&mut E>
pub fn downcast_mut<E>(&mut self) -> Option<&mut E>
Downcast the error to a mutable reference to a concrete type.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more