pub struct AnyError(/* private fields */);Expand description
Type-erased error that can wrap a StackError or any std::error::Error.
StackErrors have a blanket impl to convert into AnyError, while preserving
their call-site location info.
Errors that implement std::error::Error but not StackError can’t convert to
AnyError automatically. Use either AnyError::from_std or crate::StdResultExt::e
to convert std errors into AnyError.
This is necessary unfortunately because if we had a blanket conversion from std errors to AnyError,
this blanket conversion would also apply to StackErrors, thus losing their call-site location
info in the conversion.
Implementations§
Source§impl AnyError
impl AnyError
Sourcepub fn from_std(err: impl Error + Send + Sync + 'static) -> Self
pub fn from_std(err: impl Error + Send + Sync + 'static) -> Self
Creates an AnyError from a std error.
This captures call-site metadata.
Sourcepub fn from_anyhow(err: Error) -> Self
pub fn from_anyhow(err: Error) -> Self
Creates an AnyError from a anyhow::Error.
Sourcepub fn from_std_box(err: Box<dyn Error + Send + Sync + 'static>) -> Self
pub fn from_std_box(err: Box<dyn Error + Send + Sync + 'static>) -> Self
Creates an AnyError from a bosed std error.
This captures call-site metadata.
Sourcepub fn from_display(s: impl Display) -> Self
pub fn from_display(s: impl Display) -> Self
Creates an AnyError from any Display value by formatting it into a message.
Sourcepub fn from_string(message: String) -> Self
pub fn from_string(message: String) -> Self
Creates an AnyError from a message string.
Sourcepub fn from_stack(err: impl StackError + 'static) -> Self
pub fn from_stack(err: impl StackError + 'static) -> Self
Creates an AnyError from a StackError.
This preserves the error’s call-site metadata.
Equivalent to AnyError::from(err).
Sourcepub fn from_stack_box(err: Box<dyn StackError>) -> Self
pub fn from_stack_box(err: Box<dyn StackError>) -> Self
Creates an AnyError from a boxed StackError.
Trait Implementations§
Source§impl Error for AnyError
impl Error for AnyError
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
Source§impl StackError for AnyError
impl StackError for AnyError
Source§fn as_dyn(&self) -> &dyn StackError
fn as_dyn(&self) -> &dyn StackError
dyn StackError.