Struct error_chain_mini::ChainedError [] [src]

pub struct ChainedError<T: ErrorKind> {
    pub kind: T,
    pub context: Vec<String>,
}

Chainable error type.

See module level documentation for usage.

Fields

Methods

impl<T: ErrorKind> ChainedError<T>
[src]

[src]

Add context to ChainedError.

It's more useful to use chain_err.

[src]

Convert ChainedError<T> into ChainedError<U>.

For some reason, we can't provide this type of conversion directly as a method of ResultExt, so you have to use map_err explicitly.

Usage

mod external {
    #[derive(ErrorKind, Eq, PartialEq, Debug)]
    #[msg(short = "error in external")]
    pub struct ExtErrorKind;
    pub type Error = ChainedError<ExtErrorKind>;
    pub fn func() -> Result<(), Error> {
        Err(ExtErrorKind{}.into_with("In external::func()"))
    }
}
use external::{self, ExtErrorKind};
#[derive(ErrorKind, Eq, PartialEq, Debug)]
enum MyErrorKind {
    Internal,
    #[msg(short = "from mod 'external'", detailed = "{:?}", _0)]
    External(ExtErrorKind),
};
impl From<ExtErrorKind> for MyErrorKind {
    fn from(e: ExtErrorKind) -> MyErrorKind {
        MyErrorKind::External(e)
    }
}
type Error = ChainedError<MyErrorKind>;
let chained: Result<(), Error> = external::func().map_err(|e| e.convert("In my_func()"));
if let Err(chained) = chained {
    assert_eq!(chained.kind, MyErrorKind::External(ExtErrorKind {}));
    assert_eq!(chained.context[1], "In my_func()");
}

Trait Implementations

impl<T: ErrorKind + Clone> Clone for ChainedError<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: ErrorKind + Sync> Sync for ChainedError<T>
[src]

impl<T: ErrorKind + Send> Send for ChainedError<T>
[src]

impl<T: ErrorKind> Debug for ChainedError<T>
[src]

[src]

Formats the value using the given formatter. Read more

impl<T: ErrorKind> Error for ChainedError<T>
[src]

[src]

A short description of the error. Read more

1.0.0
[src]

The lower-level cause of this error, if any. Read more

impl<T: ErrorKind> Display for ChainedError<T>
[src]

[src]

Formats the value using the given formatter. Read more