pub struct Error(/* private fields */);Expand description
Error type used by Topcoat APIs.
Use ? to convert a compatible std::error::Error into this type.
Inspect its concrete value with downcast_ref, or
recover it with downcast. Clones share the stored error.
Backtrace capture follows the environment settings described by
backtrace.
With the anyhow feature, Error::from_anyhow converts an anyhow::Error
as well.
Implementations§
Source§impl Error
impl Error
Sourcepub fn msg(message: impl Display + Debug + Send + Sync + 'static) -> Self
pub fn msg(message: impl Display + Debug + Send + Sync + 'static) -> Self
Builds an error from a message.
Sourcepub fn from_boxed(error: Box<dyn Error + Send + Sync + 'static>) -> Self
pub fn from_boxed(error: Box<dyn Error + Send + Sync + 'static>) -> Self
Builds an error from a boxed error. Its message and sources carry over, but the concrete error inside the box is not reachable through the downcast methods.
Sourcepub fn from_anyhow(error: Error) -> Self
Available on crate feature anyhow only.
pub fn from_anyhow(error: Error) -> Self
anyhow only.Builds an error from an anyhow::Error. Its message and sources
carry over, but the concrete error inside it is not reachable through
the downcast methods.
Sourcepub fn is<E>(&self) -> bool
pub fn is<E>(&self) -> bool
Returns whether the stored error is an instance of E, looking through
context layers.
Sourcepub fn downcast<E>(self) -> Result<E, DowncastError>
pub fn downcast<E>(self) -> Result<E, DowncastError>
Attempts to move the concrete error out of this error object, looking
through context layers and discarding their
messages.
This never clones the stored error, so it only succeeds while this is
the sole handle to it. To fall back to a clone instead, use
downcast_cloned.
§Errors
Returns a DowncastError carrying the original error back, and
saying whether the stored error is not an instance of E or a clone
of it is still alive.
Sourcepub fn downcast_cloned<E>(self) -> Result<E, Self>
pub fn downcast_cloned<E>(self) -> Result<E, Self>
Sourcepub fn downcast_ref<E>(&self) -> Option<&E>
pub fn downcast_ref<E>(&self) -> Option<&E>
Borrows the concrete error, looking through
context layers.
Sourcepub fn downcast_mut<E>(&mut self) -> Result<&mut E, DowncastFailure>
pub fn downcast_mut<E>(&mut self) -> Result<&mut E, DowncastFailure>
Mutably borrows the concrete error, looking through
context layers.
§Errors
Returns a DowncastFailure saying whether the stored error is not
an instance of E or a clone of it is still alive: shared contents
cannot be handed out mutably.
Sourcepub fn backtrace(&self) -> &Backtrace
pub fn backtrace(&self) -> &Backtrace
The backtrace captured when the error was built. Capture follows the
RUST_BACKTRACE and RUST_LIB_BACKTRACE environment variables; check
Backtrace::status before relying on its contents.
Trait Implementations§
Source§impl Debug for Error
Prints the stored error’s message, its sources, and the backtrace when one
was captured; the alternate form ({:#?}) prints the stored error’s own
Debug output instead.
impl Debug for Error
Prints the stored error’s message, its sources, and the backtrace when one
was captured; the alternate form ({:#?}) prints the stored error’s own
Debug output instead.
Source§impl Display for Error
Prints the stored error’s message; the alternate form ({:#}) appends
each source after a colon.
impl Display for Error
Prints the stored error’s message; the alternate form ({:#}) appends
each source after a colon.