Skip to main content

Error

Struct Error 

Source
pub struct Error(/* private fields */);
Expand description

Type-erased error wrapper for when you don’t need to preserve the concrete type.

This is a newtype wrapper around Box<dyn StdError> that enables proper trait resolution for typed catches. It does NOT implement Error itself (to avoid trait impl conflicts), but provides access to the inner error.

Implementations§

Source§

impl Error

Source

pub fn new<E: StdError + Send + Sync + 'static>(e: E) -> Self

Create from any error type.

Source

pub fn from_box(e: Box<dyn StdError + Send + Sync + 'static>) -> Self

Create from a boxed error.

Source

pub fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static)

Get the inner error as a trait object reference.

Source

pub fn as_dyn_error(&self) -> &(dyn StdError + 'static)

Get the inner error as a trait object reference (non-Send/Sync for Error trait compat).

Source

pub fn downcast_ref<T: StdError + 'static>(&self) -> Option<&T>

Try to downcast to a specific error type.

Source

pub fn downcast<T: StdError + 'static>(self) -> Result<T, Self>

Try to downcast and consume the error.

Source

pub fn into_inner(self) -> Box<dyn StdError + Send + Sync + 'static>

Get the inner boxed error.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

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

Available on crate feature std only.
Source§

fn from(e: E) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe 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> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.