[][src]Struct extracterr::Bundled

pub struct Bundled<E, C: 'static> { /* fields omitted */ }

An Error bundled with a Context can then later be extracted from a chain of dyn Errors.

Usage

This type has two primary methods of construction, From and Bundle. The first method of construction, the From trait, only works when the type you're bundling with the error implements Default. This is useful for types like Backtraces where the context you care about is implicitly captured just by constructing the type, or for types that have a reasonable default like HttpStatusCodes defaulting to 500.

use extracterr::Bundled;

#[derive(Debug, thiserror::Error)]
#[error("just an example error")]
struct ExampleError;

struct StatusCode(u32);

impl Default for StatusCode {
    fn default() -> Self {
        Self(500)
    }
}


fn foo() -> Result<(), Bundled<ExampleError, StatusCode>> {
    Err(ExampleError)?
}

The second method of construction, the Bundle trait, lets you attach context to errors manually. This is useful for types that don't implement Default or types where you only occasionally want to override the defaults.

use extracterr::{Bundled, Bundle};

#[derive(Debug, thiserror::Error)]
#[error("just an example error")]
struct ExampleError;

struct StatusCode(u32);

fn foo() -> Result<(), Bundled<ExampleError, StatusCode>> {
    Err(ExampleError).bundle(StatusCode(404))?
}

Once context has been bundled with an error it can then be extracted by an error reporter with the Extract trait.

Implementations

impl<E, C: 'static> Bundled<E, C>[src]

pub fn inner(&self) -> &E[src]

Returns a reference to the inner error

Trait Implementations

impl<E, C> Debug for Bundled<E, C> where
    E: Error
[src]

impl<E, C> Display for Bundled<E, C> where
    E: Error
[src]

impl<E, C> Error for Bundled<E, C> where
    E: Error + 'static, 
[src]

impl<E, C> From<E> for Bundled<E, C> where
    E: Error + Send + Sync + 'static,
    C: Default
[src]

Auto Trait Implementations

impl<E, C> RefUnwindSafe for Bundled<E, C> where
    C: RefUnwindSafe,
    E: RefUnwindSafe

impl<E, C> Send for Bundled<E, C> where
    C: Send,
    E: Send

impl<E, C> Sync for Bundled<E, C> where
    C: Sync,
    E: Sync

impl<E, C> Unpin for Bundled<E, C> where
    C: Unpin,
    E: Unpin

impl<E, C> UnwindSafe for Bundled<E, C> where
    C: UnwindSafe,
    E: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.