Skip to main content

Extract

Trait Extract 

Source
pub trait Extract {
    // Required method
    fn extract<C>(&self) -> Option<&C>
       where C: 'static;
}
Expand description

Extension trait for extracting references to bundled context from dyn Error trait objects

Required Methods§

Source

fn extract<C>(&self) -> Option<&C>
where C: 'static,

§Example
use std::error::Error;
use backtrace::Backtrace;
use extracterr::{Bundled, Extract};

fn report(error: &(dyn Error + 'static)) {
    let mut source = Some(error);
    let mut ind = 0;
    let mut backtrace = None;

    while let Some(error) = source {
        source = error.source();

        if let Some(bt) = error.extract::<Backtrace>() {
            backtrace = Some(bt);
        } else {
            println!("{}: {}", ind, error);
            ind += 1;
        }
    }

    if let Some(backtrace) = backtrace {
        println!("\nBacktrace:\n{:?}", backtrace)
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Extract for dyn Error + 'static

Source§

fn extract<C>(&self) -> Option<&C>
where C: 'static,

Source§

impl Extract for dyn Error + Send + Sync + 'static

Source§

fn extract<C>(&self) -> Option<&C>
where C: 'static,

Implementors§