pub struct Error<E> { /* private fields */ }Expand description
An error container.
Error<E> is a lightweight handle to an error that can be cheaply cloned
and safely shared across threads. It preserves the original error along with
associated context such as where it occurred.
Implementations§
Source§impl<E> Error<E>
impl<E> Error<E>
Sourcepub fn new<T>(error: T, service: &'static str) -> Selfwhere
E: From<T>,
pub fn new<T>(error: T, service: &'static str) -> Selfwhere
E: From<T>,
Creates a new error container.
Captures the caller location and associates the error with a service.
Sourcepub fn forward<U, F>(self, f: F) -> Error<U>
pub fn forward<U, F>(self, f: F) -> Error<U>
Transforms the inner error into another error type.
Preserves service, backtrace, and extension data.
Source§impl<E: Clone> Error<E>
impl<E: Clone> Error<E>
Sourcepub fn set_tag<T: Into<Bytes>>(self, tag: T) -> Self
pub fn set_tag<T: Into<Bytes>>(self, tag: T) -> Self
Sets a user-defined tag on this error.
Returns the updated error.
Sourcepub fn set_service(self, name: &'static str) -> Self
pub fn set_service(self, name: &'static str) -> Self
Sets the service responsible for this error.
Returns the updated error.
Sourcepub fn map<U, F>(self, f: F) -> Error<U>where
F: FnOnce(E) -> U,
pub fn map<U, F>(self, f: F) -> Error<U>where
F: FnOnce(E) -> U,
Maps the inner error into a new error type.
Preserves service, backtrace, and extension data.
Sourcepub fn try_map<T, U, F>(self, f: F) -> Result<T, Error<U>>
pub fn try_map<T, U, F>(self, f: F) -> Result<T, Error<U>>
Try to map inner error to new error.
Preserves service, backtrace, and extension data.
Sourcepub fn insert_item<T: Sync + Send + 'static>(self, val: T) -> Self
pub fn insert_item<T: Sync + Send + 'static>(self, val: T) -> Self
Attaches a typed value to this Error.
This value can be retrieved later using get_item::<T>().
Trait Implementations§
Source§impl<E: Error + 'static> Error for Error<E>
impl<E: Error + 'static> Error for Error<E>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()