Skip to main content

Error

Struct Error 

Source
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

Source

pub fn msg(message: impl Display + Debug + Send + Sync + 'static) -> Self

Builds an error from a message.

Source

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.

Source

pub fn from_anyhow(error: Error) -> Self

Available on crate feature 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.

Source

pub fn context(self, context: impl Display + Send + Sync + 'static) -> Self

Wraps this error in a context message, which becomes its Display output. The wrapped error stays reachable through source, chain, and the downcast methods.

Source

pub fn is<E>(&self) -> bool
where E: Error + Send + Sync + 'static,

Returns whether the stored error is an instance of E, looking through context layers.

Source

pub fn downcast<E>(self) -> Result<E, DowncastError>
where E: Error + Send + Sync + 'static,

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.

Source

pub fn downcast_cloned<E>(self) -> Result<E, Self>
where E: Error + Send + Sync + Clone + 'static,

Attempts to downcast the error object to a concrete type, looking through context layers.

The stored error is moved out when this is the sole handle to it and cloned otherwise.

§Errors

Returns Err(Self) if the stored error is not an instance of E, handing back the original error unchanged.

Source

pub fn downcast_ref<E>(&self) -> Option<&E>
where E: Error + Send + Sync + 'static,

Borrows the concrete error, looking through context layers.

Source

pub fn downcast_mut<E>(&mut self) -> Result<&mut E, DowncastFailure>
where E: Error + Send + Sync + 'static,

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.

Source

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.

Source

pub fn chain(&self) -> impl Iterator<Item = &(dyn Error + 'static)>

The stored error followed by each of its sources, outermost first.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Error

Borrows the stored error as an error trait object.

Source§

type Target = dyn Error + Send + Sync

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for Error

Prints the stored error’s message; the alternate form ({:#}) appends each source after a colon.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E> From<E> for Error
where E: Error + Send + Sync + 'static,

Source§

fn from(error: E) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Box<dyn Error + Send + Sync + 'static>

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.