[−][src]Struct chainerror::ChainError
chains an inner error kind T with a causing error
Methods
impl<T: 'static + Display + Debug> ChainError<T>[src]
pub fn new(
kind: T,
error_cause: Option<Box<dyn Error + 'static>>,
occurrence: Option<(u32, &'static str)>
) -> Self[src]
kind: T,
error_cause: Option<Box<dyn Error + 'static>>,
occurrence: Option<(u32, &'static str)>
) -> Self
Use the cherr!() or mstrerr!() macro instead of calling this directly
pub fn root_cause(&self) -> Option<&(dyn Error + 'static)>[src]
return the root cause of the error chain, if any exists
pub fn find_cause<U: Error + 'static>(&self) -> Option<&U>[src]
Find the first error cause of type U, if any exists
Examples
fn do_some_io() -> Result<(), Box<Error>> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); fn func2() -> Result<(), Box<Error>> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; Ok(()) } derive_str_cherr!(Func1Error); fn func1() -> Result<(), Box<Error>> { func2().map_err(mstrerr!(Func1Error, "func1 error"))?; Ok(()) } fn main() { if let Err(e) = func1() { if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() { assert!(f1err.find_cause::<io::Error>().is_some()); assert!(f1err.find_chain_cause::<Func2Error>().is_some()); } } }
pub fn find_chain_cause<U: Error + 'static>(&self) -> Option<&ChainError<U>>[src]
Find the first error cause of type ChainError<U>, if any exists
Same as find_cause, but hides the ChainError<U> implementation internals
Examples
// Instead of writing err.find_cause::<ChainError<FooError>>(); // leave out the ChainError<FooError> implementation detail err.find_chain_cause::<FooError>();
pub fn find_kind_or_cause<U: Error + 'static>(&self) -> Option<&U>[src]
Find the first error cause of type ChainError<U> or U, if any exists and return U
Same as find_cause and find_chain_cause, but hides the ChainError<U> implementation internals
Examples
// Instead of writing err.find_cause::<ChainError<FooErrorKind>>(); // and/or err.find_chain_cause::<FooErrorKind>(); // and/or err.find_cause::<FooErrorKind>(); // leave out the ChainError<FooErrorKind> implementation detail err.find_chain_or_kind::<FooErrorKind>();
pub fn kind(&self) -> &T[src]
Return a reference to T of ChainError<T>
Examples
fn do_some_io() -> Result<(), Box<Error>> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); fn func2() -> Result<(), Box<Error>> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; Ok(()) } #[derive(Debug)] enum Func1ErrorKind { Func2, IO(String), } /// impl ::std::fmt::Display for Func1ErrorKind {…} fn func1() -> ChainResult<(), Func1ErrorKind> { func2().map_err(|e| cherr!(e, Func1ErrorKind::Func2))?; do_some_io().map_err(|e| cherr!(e, Func1ErrorKind::IO("bar.txt".into())))?; Ok(()) } fn main() { if let Err(e) = func1() { match e.kind() { Func1ErrorKind::Func2 => {}, Func1ErrorKind::IO(filename) => panic!(), } } }
pub fn iter(&self) -> impl Iterator<Item = &(dyn Error + 'static)>[src]
Returns an Iterator over all error causes/sources
Example
Trait Implementations
impl<U: 'static + Display + Debug> ChainErrorDown for ChainError<U>[src]
fn is_chain<T: 'static + Display + Debug>(&self) -> bool[src]
fn downcast_chain_ref<T: 'static + Display + Debug>(
&self
) -> Option<&ChainError<T>>[src]
&self
) -> Option<&ChainError<T>>
fn downcast_chain_mut<T: 'static + Display + Debug>(
&mut self
) -> Option<&mut ChainError<T>>[src]
&mut self
) -> Option<&mut ChainError<T>>
impl<T: 'static + Display + Debug> Display for ChainError<T>[src]
impl<T: 'static + Display + Debug> Deref for ChainError<T>[src]
impl<T: 'static + Display + Debug> Debug for ChainError<T>[src]
impl<T: 'static + Display + Debug> Error for ChainError<T>[src]
fn source(&self) -> Option<&(dyn Error + 'static)>[src]
fn description(&self) -> &str1.0.0[src]
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&dyn Error>1.0.0[src]
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
impl<T: 'static + Display + Debug, '_> Error for &'_ ChainError<T>[src]
fn source(&self) -> Option<&(dyn Error + 'static)>[src]
fn description(&self) -> &str1.0.0[src]
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&dyn Error>1.0.0[src]
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
impl<T: 'static + Display + Debug, '_> Error for &'_ mut ChainError<T>[src]
fn source(&self) -> Option<&(dyn Error + 'static)>[src]
fn description(&self) -> &str1.0.0[src]
This method is soft-deprecated. Read more
fn cause(&self) -> Option<&dyn Error>1.0.0[src]
replaced by Error::source, which can support downcasting
The lower-level cause of this error, if any. Read more
Auto Trait Implementations
impl<T> !Send for ChainError<T>
impl<T> !Sync for ChainError<T>
Blanket Implementations
impl<T, U> ChainErrorFrom for U where
T: Into<U>,
U: 'static + Display + Debug, [src]
T: Into<U>,
U: 'static + Display + Debug,
fn chain_error_from(T, Option<(u32, &'static str)>) -> ChainError<U>[src]
impl<T, U> IntoChainError for T where
U: ChainErrorFrom<T>, [src]
U: ChainErrorFrom<T>,
fn into_chain_error(Self, Option<(u32, &'static str)>) -> ChainError<U>[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> From for T[src]
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,