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
kind: T
context: Vec<String>
Methods
impl<T: ErrorKind> ChainedError<T>[src]
pub fn chain<C: ErrorContext>(self, c: C) -> Self[src]
Add context to ChainedError.
It's more useful to use chain_err.
pub fn convert<U, C>(self, c: C) -> ChainedError<U> where
U: ErrorKind + From<T>,
C: ErrorContext, [src]
U: ErrorKind + From<T>,
C: ErrorContext,
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]
fn clone(&self) -> Self[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)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]
fn fmt(&self, f: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more
impl<T: ErrorKind> Error for ChainedError<T>[src]
fn description(&self) -> &str[src]
A short description of the error. Read more
fn cause(&self) -> Option<&Error>1.0.0[src]
The lower-level cause of this error, if any. Read more