error_chain

Trait ChainedError

Source
pub trait ChainedError:
    Error
    + Send
    + 'static {
    type ErrorKind;

    // Required methods
    fn from_kind(kind: Self::ErrorKind) -> Self
       where Self: Sized;
    fn with_chain<E, K>(error: E, kind: K) -> Self
       where Self: Sized,
             E: Error + Send + 'static,
             K: Into<Self::ErrorKind>;
    fn kind(&self) -> &Self::ErrorKind;
    fn iter(&self) -> Iter<'_> ;
    fn backtrace(&self) -> Option<&Backtrace>;
    fn chain_err<F, EK>(self, error: F) -> Self
       where F: FnOnce() -> EK,
             EK: Into<Self::ErrorKind>;

    // Provided method
    fn display_chain<'a>(&'a self) -> DisplayChain<'a, Self> { ... }
}
Expand description

This trait is implemented on all the errors generated by the error_chain macro.

Required Associated Types§

Source

type ErrorKind

Associated kind type.

Required Methods§

Source

fn from_kind(kind: Self::ErrorKind) -> Self
where Self: Sized,

Constructs an error from a kind, and generates a backtrace.

Source

fn with_chain<E, K>(error: E, kind: K) -> Self
where Self: Sized, E: Error + Send + 'static, K: Into<Self::ErrorKind>,

Constructs a chained error from another error and a kind, and generates a backtrace.

Source

fn kind(&self) -> &Self::ErrorKind

Returns the kind of the error.

Source

fn iter(&self) -> Iter<'_>

Iterates over the error chain.

Source

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

Returns the backtrace associated with this error.

Source

fn chain_err<F, EK>(self, error: F) -> Self
where F: FnOnce() -> EK, EK: Into<Self::ErrorKind>,

Extends the error chain with a new entry.

Provided Methods§

Source

fn display_chain<'a>(&'a self) -> DisplayChain<'a, Self>

Returns an object which implements Display for printing the full context of this error.

The full cause chain and backtrace, if present, will be printed.

Examples found in repository?
examples/quickstart.rs (line 59)
52
53
54
55
56
57
58
59
60
61
62
fn alternative_main() {
    if let Err(ref e) = run() {
        use error_chain::ChainedError;
        use std::io::Write; // trait which holds `display_chain`
        let stderr = &mut ::std::io::stderr();
        let errmsg = "Error writing to stderr";

        writeln!(stderr, "{}", e.display_chain()).expect(errmsg);
        ::std::process::exit(1);
    }
}

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.

Implementors§

Source§

impl ChainedError for error_chain::example_generated::inner::Error

Source§

impl ChainedError for error_chain::example_generated::Error