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
impl Error
Sourcepub fn with_error<E>(err: E) -> Builder<E, Stateless, Immediate<Empty>, Blank>
pub fn with_error<E>(err: E) -> Builder<E, Stateless, Immediate<Empty>, Blank>
Starts building an Error from a source error.
Sourcepub fn with_state<S>(state: S) -> Builder<Nae, S, Immediate<Empty>, Blank>where
S: State,
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.
Sourcepub fn with_payload<P>(
payload: P,
) -> Builder<Nae, Stateless, Immediate<P>, Blank>
pub fn with_payload<P>( payload: P, ) -> Builder<Nae, Stateless, Immediate<P>, Blank>
Starts building an Error with a payload.
Sourcepub fn with_payload_fn<F>(payload_fn: F) -> Builder<Nae, Stateless, F, Blank>where
F: PayloadFn,
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.
Sourcepub fn with_context<L>(_ty: L) -> Builder<Nae, Stateless, Immediate<Empty>, L>where
L: Context,
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.
Sourcepub fn with_context_ty<L>() -> Builder<Nae, Stateless, Immediate<Empty>, L>
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§impl<S> Error<S>
impl<S> Error<S>
Sourcepub fn erase_ref(&self) -> &(impl Error + Send + Sync + 'static)
pub fn erase_ref(&self) -> &(impl Error + Send + Sync + 'static)
Returns a reference to an opaque Error.
Sourcepub fn from_error<E>(err: E) -> Self
pub fn from_error<E>(err: E) -> Self
Creates an Error from any Error.
Sourcepub fn from_context<L>(_ty: L) -> Selfwhere
L: Literal,
pub fn from_context<L>(_ty: L) -> Selfwhere
L: Literal,
Creates an Error from a typed literal value.
Sourcepub fn from_context_ty<L>() -> Selfwhere
L: Literal,
pub fn from_context_ty<L>() -> Selfwhere
L: Literal,
Creates an Error from a typed literal, inferred at the call site.
Sourcepub fn from_payload<P>(payload: P) -> Self
pub fn from_payload<P>(payload: P) -> Self
Creates an Error from a payload.
Sourcepub fn from_boxed(value: Box<dyn Error + Send + Sync + 'static>) -> Self
pub fn from_boxed(value: Box<dyn Error + Send + Sync + 'static>) -> Self
Creates an Error from a boxed error.
Sourcepub fn try_into_stateless(self) -> Result<Error, Self>
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.
Sourcepub fn context(&self) -> Option<&(dyn Display + Send + Sync + 'static)>
pub fn context(&self) -> Option<&(dyn Display + Send + Sync + 'static)>
Returns a reference to the context, if present.
Sourcepub fn payload(&self) -> Option<&(dyn Display + Send + Sync + 'static)>
pub fn payload(&self) -> Option<&(dyn Display + Send + Sync + 'static)>
Returns a reference to the payload, if present.
Sourcepub fn has_source_of<E>(&self) -> boolwhere
E: Error + 'static,
pub fn has_source_of<E>(&self) -> boolwhere
E: Error + 'static,
Returns true if the wrapped source error is of type E.
Sourcepub fn source(&self) -> Option<&(dyn Error + 'static)>
pub fn source(&self) -> Option<&(dyn Error + 'static)>
Returns a reference to the source error, if any.
Sourcepub fn downcast_source_ref<E>(&self) -> Option<&E>where
E: Error + 'static,
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.
Sourcepub fn downcast_source_mut<E>(&mut self) -> Option<&mut E>where
E: Error + 'static,
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.
Sourcepub fn has_payload_of<P>(&self) -> boolwhere
P: 'static,
pub fn has_payload_of<P>(&self) -> boolwhere
P: 'static,
Returns true if the attached payload is of type P.
Sourcepub fn downcast_payload_ref<P>(&self) -> Option<&P>where
P: 'static,
pub fn downcast_payload_ref<P>(&self) -> Option<&P>where
P: 'static,
Attempts to downcast the payload to P by shared reference.
Sourcepub fn downcast_payload_mut<P>(&mut self) -> Option<&mut P>where
P: 'static,
pub fn downcast_payload_mut<P>(&mut self) -> Option<&mut P>where
P: 'static,
Attempts to downcast the payload to P by mutable reference.
Sourcepub fn into_source(self) -> Option<Box<dyn Error + Send + Sync + 'static>>
pub fn into_source(self) -> Option<Box<dyn Error + Send + Sync + 'static>>
Consumes self and returns the boxed source error, if any.
Sourcepub fn chain(&self) -> impl Iterator<Item = &(dyn Error + 'static)>
pub fn chain(&self) -> impl Iterator<Item = &(dyn Error + 'static)>
Iterates over the source error chain, starting from the immediate source.
Sourcepub fn with_phantom_state<S2>(self) -> Error<S2>
pub fn with_phantom_state<S2>(self) -> Error<S2>
Converts to an error of another state without providing the state value.
Source§impl<S> Error<S>where
S: State,
impl<S> Error<S>where
S: State,
Sourcepub fn from_state(state: S) -> Self
pub fn from_state(state: S) -> Self
Creates an Error from a state value.
Sourcepub fn into_parts<P, E>(
self,
) -> (Option<S>, Option<&'static str>, Option<P>, Option<E>)where
E: 'static,
P: 'static,
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.
Sourcepub fn extract_state(self) -> Result<(S, Vacant<S>), Error>
pub fn extract_state(self) -> Result<(S, Vacant<S>), Error>
Attempts to extract the state.