Skip to main content

Error

Struct Error 

Source
pub struct Error<S = Stateless>(/* private fields */)
where
    S: State + ?Sized;
Expand description

An error type that can carry optional state, source, context, and payload.

Implementations§

Source§

impl Error

Source

pub fn with_error<E>(err: E) -> Builder<E, Stateless, Immediate<Empty>, Blank>

Starts building an Error from a source error.

Source

pub fn with_state<S>(state: S) -> Builder<Nae, S, Immediate<Empty>, Blank>
where S: State,

Starts building an Error with a typed state.

The state is inlined when no source or payload is attached.

Source

pub fn with_payload<P>( payload: P, ) -> Builder<Nae, Stateless, Immediate<P>, Blank>
where P: Display + Send + Sync + 'static,

Starts building an Error with a payload.

Source

pub fn with_payload_fn<F>(payload_fn: F) -> Builder<Nae, Stateless, F, Blank>
where F: PayloadFn,

Starts building an Error with a lazily evaluated payload.

The closure payload_fn is called only when the error is materialized.

Source

pub fn with_context<L>(_ty: L) -> Builder<Nae, Stateless, Immediate<Empty>, L>
where L: Context,

Starts building an Error with a typed literal context.

For dynamic content, use with_payload instead.

Source

pub fn with_context_ty<L>() -> Builder<Nae, Stateless, Immediate<Empty>, L>

Starts building an Error with a literal context type, inferred at the call site.

Source

pub fn into_parts<P, E>(self) -> (Option<&'static str>, Option<P>, Option<E>)
where E: 'static, P: 'static,

Extracts the context, payload, and source error.

Returns None when the corresponding requested type does not match.

Source

pub fn stateless(self) -> Self

Helper for type inference when the state is not needed.

Source§

impl<S> Error<S>
where S: State + ?Sized,

Source

pub fn erase(self) -> impl Error + Send + Sync + 'static

Returns an opaque Error.

Source

pub fn erase_ref(&self) -> &(impl Error + Send + Sync + 'static)

Returns a reference to an opaque Error.

Source

pub fn from_error<E>(err: E) -> Self
where E: Error + Send + Sync + 'static,

Creates an Error from any Error.

Source

pub fn from_context<L>(_ty: L) -> Self
where L: Literal,

Creates an Error from a typed literal value.

Source

pub fn from_context_ty<L>() -> Self
where L: Literal,

Creates an Error from a typed literal, inferred at the call site.

Source

pub fn from_payload<P>(payload: P) -> Self
where P: Display + Send + Sync + 'static,

Creates an Error from a payload.

Source

pub fn from_boxed(value: Box<dyn Error + Send + Sync + 'static>) -> Self

Creates an Error from a boxed error.

Source

pub fn has_state(&self) -> bool

Returns true if there is a state stored inside the error.

Source

pub fn try_into_stateless(self) -> Result<Error, Self>

Converts to a stateless error. Returns Err when no extra details remain after dropping the state.

Source

pub fn context(&self) -> Option<&(dyn Display + Send + Sync + 'static)>

Returns a reference to the context, if present.

Source

pub fn payload(&self) -> Option<&(dyn Display + Send + Sync + 'static)>

Returns a reference to the payload, if present.

Source

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

Returns true if the wrapped source error is of type E.

Source

pub fn source(&self) -> Option<&(dyn Error + 'static)>

Returns a reference to the source error, if any.

Source

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

Attempts to downcast the wrapped source error to E by shared reference.

Source

pub fn downcast_source_mut<E>(&mut self) -> Option<&mut E>
where E: Error + 'static,

Attempts to downcast the wrapped source error to E by mutable reference.

Source

pub fn has_payload_of<P>(&self) -> bool
where P: 'static,

Returns true if the attached payload is of type P.

Source

pub fn downcast_payload_ref<P>(&self) -> Option<&P>
where P: 'static,

Attempts to downcast the payload to P by shared reference.

Source

pub fn downcast_payload_mut<P>(&mut self) -> Option<&mut P>
where P: 'static,

Attempts to downcast the payload to P by mutable reference.

Source

pub fn into_source(self) -> Option<Box<dyn Error + Send + Sync + 'static>>

Consumes self and returns the boxed source error, if any.

Source

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

Iterates over the source error chain, starting from the immediate source.

Source

pub fn with_phantom_state<S2>(self) -> Error<S2>
where S2: State + ?Sized,

Converts to an error of another state without providing the state value.

Source

pub fn backtrace(&self) -> Option<&Backtrace>

Available on crate feature backtrace only.

Returns the backtrace, if any.

Source§

impl<S> Error<S>
where S: State,

Source

pub fn from_state(state: S) -> Self

Creates an Error from a state value.

Source

pub fn state(&self) -> Option<&S>

Returns a reference to the attached state.

Source

pub fn into_parts<P, E>( self, ) -> (Option<S>, Option<&'static str>, Option<P>, Option<E>)
where E: 'static, P: 'static,

Consumes self and returns the state, context, payload, and error.

Returns None when the requested types do not match.

Source

pub fn extract_state(self) -> Result<(S, Vacant<S>), Error>

Attempts to extract the state.

Source

pub fn map_state<F, S2>(self, f: F) -> Error<S2>
where F: FnOnce(S) -> S2, S2: State,

Source

pub fn lift_state<S2>(self) -> Error<S2>
where S2: From<S> + State,

Trait Implementations§

Source§

impl<S> Debug for Error<S>
where S: State + ?Sized,

Source§

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

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

impl<S> Deref for Error<S>
where S: State + ?Sized,

Source§

type Target = dyn Error + Sync + Send

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<S> Display for Error<S>
where S: State + ?Sized,

Source§

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

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

impl<S> ErrorExt for Error<S>
where S: State + ?Sized,

Source§

type Result<E> = E

Source§

type S = S

Source§

fn build_error(self) -> Self::Result<Error<Self::S>>

Materializes the final Error<Self::S>.
Source§

fn erase_error(self) -> Self::Result<impl Error + Send + Sync + 'static>

Materializes and then erases the state, returning an opaque impl Error.
Source§

impl<E, S, F, L> From<Builder<E, S, F, L>> for Error<S>
where F: PayloadFn, E: Error + Send + Sync + 'static, S: State + ?Sized, L: Context + ?Sized,

Source§

fn from(value: Builder<E, S, F, L>) -> Self

Converts to this type from the input type.
Source§

impl<E, S, F, L> From<Builder<E, Stateless, F, L>> for Error<S>
where F: PayloadFn, E: Error + Send + Sync + 'static, S: State, L: Context + ?Sized,

Source§

fn from(value: Builder<E, Stateless, F, L>) -> Self

Converts to this type from the input type.
Source§

impl<S1, S, F, L> From<Builder<Error<S1>, S, F, L>> for Error<S>
where S1: State + ?Sized, F: PayloadFn, S: State + ?Sized, L: Context + ?Sized,

Source§

fn from(value: Builder<Error<S1>, S, F, L>) -> Self

Converts to this type from the input type.
Source§

impl<S1, S, F, L> From<Builder<Error<S1>, Stateless, F, L>> for Error<S>
where S1: State + ?Sized, F: PayloadFn, S: State, L: Context + ?Sized,

Source§

fn from(value: Builder<Error<S1>, Stateless, F, L>) -> Self

Converts to this type from the input type.
Source§

impl<E, S> From<E> for Error<S>
where E: Error + Send + Sync + 'static, S: State + ?Sized,

Source§

fn from(err: E) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Error<S>> for Box<dyn Error + 'static>
where S: State + ?Sized,

Source§

fn from(value: Error<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Error<S>> for Box<dyn Error + Send + 'static>
where S: State + ?Sized,

Source§

fn from(value: Error<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Error<S>> for Box<dyn Error + Send + Sync + 'static>
where S: State + ?Sized,

Source§

fn from(value: Error<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Error<S>> for Box<dyn Error + Sync + 'static>
where S: State + ?Sized,

Source§

fn from(value: Error<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Error> for Error<S>
where S: State,

Source§

fn from(value: Error) -> Self

Converts to this type from the input type.
Source§

impl<S1> StateExt for Error<S1>
where S1: State,

Source§

type T = ()

Source§

type S = S1

Source§

type Result<T, E> = E

Source§

fn extract_state( self, ) -> Result<Self::Result<Self::T, (Self::S, Vacant<Self::S>)>, Error>
where Self::S: Sized,

Extracts the state if it has been set.
Source§

fn map_state<F, S>(self, f: F) -> Self::Result<Self::T, Error<S>>
where F: FnOnce(Self::S) -> S, S: State,

Source§

fn lift_state<S>(self) -> Self::Result<Self::T, Error<S>>
where S: State + From<Self::S>, Self: Sized,

Auto Trait Implementations§

§

impl<S> Freeze for Error<S>
where S: ?Sized,

§

impl<S> RefUnwindSafe for Error<S>
where <S as State>::Repr: RefUnwindSafe, S: ?Sized,

§

impl<S> Send for Error<S>
where S: ?Sized,

§

impl<S> Sync for Error<S>
where S: ?Sized,

§

impl<S> Unpin for Error<S>
where <S as State>::Repr: Unpin, S: ?Sized,

§

impl<S> UnsafeUnpin for Error<S>
where S: ?Sized,

§

impl<S> UnwindSafe for Error<S>
where <S as State>::Repr: UnwindSafe, S: ?Sized,

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<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> State for T
where T: Debug + Send + Sync + 'static,

Source§

type Repr = T

The type used to store the state inside Error.
Source§

fn into_repr(self) -> <T as State>::Repr

Converts self into its stored representation.
Source§

fn from_repr(this: <T as State>::Repr) -> T
where T: Sized,

Recovers the state from its stored representation.
Source§

fn from_repr_ref(this: &<T as State>::Repr) -> &T
where T: Sized,

Recovers a reference to the state from a reference to its stored representation.
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.