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.
It is Send and Sync when E is. It preserves the original error along
with associated context such as the location where it occurred, the responsible
service, a tag, a backtrace, and extension data.
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 an error container associated with a service.
Captures the caller location and associates the error with a service.
Sourcepub fn from_err<T>(error: T) -> Selfwhere
E: From<T>,
pub fn from_err<T>(error: T) -> Selfwhere
E: From<T>,
Creates an error container without service attribution.
Captures the caller location.
Source§impl<E: Clone> Error<E>
impl<E: Clone> Error<E>
Sourcepub fn with_tag<T: Into<Bytes>>(self, tag: T) -> Self
pub fn with_tag<T: Into<Bytes>>(self, tag: T) -> Self
Sets a user-defined tag on this error.
Returns the updated error.
Sourcepub fn with_service(self, name: &'static str) -> Self
pub fn with_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 using the provided closure.
Preserves tag, service, backtrace, and extension data.
Sourcepub fn map_err<U>(self) -> Error<U>where
U: From<E>,
pub fn map_err<U>(self) -> Error<U>where
U: From<E>,
Converts the inner error into a new error type via U: From<E>.
Preserves tag, 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>>
Tries to map the inner error into a value or another error type.
On error, preserves tag, service, backtrace, and extension data.
Sourcepub fn into_error(self) -> E
pub fn into_error(self) -> E
Consumes this error and returns the inner error value.
Trait Implementations§
Source§impl<E: ErrorDiagnostic> AsError for Error<E>
impl<E: ErrorDiagnostic> AsError for Error<E>
impl<E> Eq for Error<E>where
E: Eq,
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()