Skip to main content

Exn

Struct Exn 

Source
pub struct Exn<E = Untyped>
where E: Error + Send + Sync + 'static,
{ /* private fields */ }
Expand description

An exception type that can hold an error tree and the call site.

While an error chain, a list, is automatically created when raise and friends are invoked, one can also use Exn::raise_all to create an error that has multiple causes.

§Warning: source() information is stringified and type-erased

All source() values are turned into frames, but lose their type information completely. This is because they are only seen as reference and thus can’t be stored.

§Exn == Exn<Untyped>

Exn act’s like Box<dyn std::error::Error + Send + Sync + 'static>, but with the capability to store a tree of errors along with their call sites.

§Visualisation

Linearized trees during display make a list of 3 children indistinguishable from 3 errors where each is the child of the other.

§Debug

  • locations: ✔️
  • error display: Display
  • tree mode: linearized

§Debug + Alternate

  • locations: ❌
  • error display: Display
  • tree mode: linearized

§Display

  • locations: ❌
  • error display: Debug
  • tree mode: None

§Display + Alternate

  • locations: ❌
  • error display: Debug
  • tree mode: verbatim

Implementations§

Source§

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

Source

pub fn new(error: E) -> Exn<E>

Available on crate feature mailmap only.

Create a new exception with the given error.

This will automatically walk the source chain of the error and add them as children frames.

See also ErrorExt::raise for a fluent way to convert an error into an Exn instance.

Note that sources of error are degenerated to their string representation and all type information is erased.

Source

pub fn raise_all<T, I>(children: I, err: E) -> Exn<E>
where T: Error + Send + Sync + 'static, I: IntoIterator, <I as IntoIterator>::Item: Into<Exn<T>>,

Available on crate feature mailmap only.

Create a new exception with the given error and children.

Source

pub fn raise<T>(self, err: T) -> Exn<T>
where T: Error + Send + Sync + 'static,

Available on crate feature mailmap only.

Raise a new exception; this will make the current exception a child of the new one.

Source

pub fn chain<T>(self, err: impl Into<Exn<T>>) -> Exn<E>
where T: Error + Send + Sync + 'static,

Available on crate feature mailmap only.

Use the current exception as the head of a chain, adding err to its children.

Source

pub fn chain_all<T, I>(self, errors: I) -> Exn<E>
where T: Error + Send + Sync + 'static, I: IntoIterator, <I as IntoIterator>::Item: Into<Exn<T>>,

Available on crate feature mailmap only.

Use the current exception the head of a chain, adding errors to its children.

Source

pub fn drain_children(&mut self) -> impl Iterator<Item = Exn>

Available on crate feature mailmap only.

Drain all sources of this error as untyped Exn.

This is useful if one wants to re-organise errors, and the error layout is well known.

Source

pub fn erased(self) -> Exn

Available on crate feature mailmap only.

Erase the type of this instance and turn it into a bare Exn.

Source

pub fn error(&self) -> &E

Available on crate feature mailmap only.

Return the current exception.

Source

pub fn into_box(self) -> Box<E>

Available on crate feature mailmap only.

Discard all error context and return the underlying error in a Box.

This is useful to retain the allocation, as internally it’s also stored in a box, when comparing it to Self::into_inner().

Source

pub fn into_inner(self) -> E

Available on crate feature mailmap only.

Discard all error context and return the underlying error.

This may be needed to obtain something that once again implements Error. Note that this destroys the internal Box and moves the value back onto the stack.

Source

pub fn into_error(self) -> Error

Available on crate feature mailmap only.

Turn ourselves into a top-level Error that implements std::error::Error.

Source

pub fn into_chain(self) -> ChainedError

Available on crate feature mailmap only.

Convert this error tree into a chain of errors, breadth first, which flattens the tree but retains all type dynamic type information.

This is useful for inter-op with anyhow.

Source

pub fn frame(&self) -> &Frame

Available on crate feature mailmap only.

Return the underlying exception frame.

Source

pub fn iter(&self) -> impl Iterator<Item = &Frame>

Available on crate feature mailmap only.

Iterate over all frames in breadth-first order. The first frame is this instance, followed by all of its children.

Source

pub fn downcast_any_ref<T>(&self) -> Option<&T>
where T: Error + 'static,

Available on crate feature mailmap only.

Iterate over all frames and find one that downcasts into error of type T. Note that the search includes this instance as well.

Trait Implementations§

Source§

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

Source§

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

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

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

Source§

type Target = E

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Exn<E> as Deref>::Target

Dereferences the value.
Source§

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

Source§

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

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

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

Source§

fn from(error: E) -> Exn<E>

Converts to this type from the input type.
Source§

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

Source§

fn from(err: Exn<E>) -> Box<Frame>

Converts to this type from the input type.
Source§

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

Source§

fn from(err: Exn<E>) -> Error

Converts to this type from the input type.
Source§

impl From<Exn<ValidationError>> for Error

Source§

fn from(source: Exn<ValidationError>) -> Error

Converts to this type from the input type.
Source§

impl From<Frame> for Exn

Source§

fn from(frame: Frame) -> Exn

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<E> Freeze for Exn<E>

§

impl<E = Untyped> !RefUnwindSafe for Exn<E>

§

impl<E> Send for Exn<E>

§

impl<E> Sync for Exn<E>

§

impl<E> Unpin for Exn<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Exn<E>

§

impl<E = Untyped> !UnwindSafe for Exn<E>

Blanket Implementations§

Source§

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

Source§

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more
Source§

fn load(&self) -> <P as Access<T>>::Guard

The loading method. Read more
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, A> DynAccess<T> for A
where A: Access<T>, <A as Access<T>>::Guard: 'static,

Source§

fn load(&self) -> DynGuard<T>

The equivalent of Access::load.
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<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> Same for T

Source§

type Output = T

Should always be Self
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.