Trait error_chain_mini::ResultExt
[−]
[src]
pub trait ResultExt {
type OkType;
type ErrType;
fn chain_err<C, K>(
self,
context: C
) -> Result<Self::OkType, ChainedError<K>>
where
K: ErrorKind,
C: ErrorContext,
Self::ErrType: Into<ChainedError<K>>;
fn into_chained<C, K>(
self,
context: C
) -> Result<Self::OkType, ChainedError<K>>
where
K: ErrorKind + From<Self::ErrType>,
C: ErrorContext;
}Result extension to integrate with ChainedError
Associated Types
Required Methods
fn chain_err<C, K>(self, context: C) -> Result<Self::OkType, ChainedError<K>> where
K: ErrorKind,
C: ErrorContext,
Self::ErrType: Into<ChainedError<K>>,
K: ErrorKind,
C: ErrorContext,
Self::ErrType: Into<ChainedError<K>>,
Takes Result and add context, if self is Err.
Usage
use error_chain_mini::*; #[derive(ErrorKind, Eq, PartialEq, Debug)] #[msg(short = "My Error")] struct MyError; fn my_func() -> Result<(), ChainedError<MyError>>{ let chained = MyError{}.into_with("Error in my_func"); Err(chained) } let chained = my_func().chain_err("Chained"); assert!(chained.is_err()); if let Err(e) = chained { let msg = format!("{}", e); assert_eq!(msg, r#"--- ChainedError: kind: My Error context 0: Error in my_func context 1: Chained --- "#); }
fn into_chained<C, K>(self, context: C) -> Result<Self::OkType, ChainedError<K>> where
K: ErrorKind + From<Self::ErrType>,
C: ErrorContext,
K: ErrorKind + From<Self::ErrType>,
C: ErrorContext,
Takes Result and context then convert its error type into ChainedError with given context.
Usage
use error_chain_mini::*; use std::io; use std::fs::File; #[derive(Debug, ErrorKind)] enum MyError { #[msg(short = "io error", detailed = "{:?}", _0)] Io(io::Error), Misc } impl From<io::Error> for MyError { fn from(e: io::Error) -> Self { MyError::Io(e) } } let file: Result<_, ChainedError<MyError>> = File::open("not_existing_file").into_chained("In io()");
Implementations on Foreign Types
impl<T, E> ResultExt for Result<T, E>[src]
type OkType = T
type ErrType = E
fn chain_err<C, K>(self, context: C) -> Result<Self::OkType, ChainedError<K>> where
K: ErrorKind,
C: ErrorContext,
Self::ErrType: Into<ChainedError<K>>, [src]
K: ErrorKind,
C: ErrorContext,
Self::ErrType: Into<ChainedError<K>>,
fn into_chained<C, K>(self, context: C) -> Result<Self::OkType, ChainedError<K>> where
K: ErrorKind + From<Self::ErrType>,
C: ErrorContext, [src]
K: ErrorKind + From<Self::ErrType>,
C: ErrorContext,