pub struct Bundled<E, C: 'static> { /* private fields */ }Expand description
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.