Struct chainerror::ChainError [−][src]
chains an inner error kind T
with a causing error
Implementations
impl<T: 'static + Display + Debug> ChainError<T>
[src]
pub fn new(
kind: T,
error_cause: Option<Box<dyn Error + Send + Sync + 'static>>,
occurrence: Option<String>
) -> Self
[src]
kind: T,
error_cause: Option<Box<dyn Error + Send + Sync + 'static>>,
occurrence: Option<String>
) -> Self
Use the context()
or map_context()
Result methods 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
use chainerror::prelude::v1::*; use std::error::Error; use std::io; fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_context!(Func2Error); fn func2() -> Result<(), Box<dyn Error + Send + Sync>> { let filename = "foo.txt"; do_some_io().context(Func2Error(format!("Error reading '{}'", filename)))?; Ok(()) } derive_str_context!(Func1Error); fn func1() -> Result<(), Box<dyn Error + Send + Sync>> { func2().context(Func1Error("func1 error".into()))?; Ok(()) } 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_kind_or_cause::<FooErrorKind>();
pub fn kind(&self) -> &T
[src]
Return a reference to T of ChainError<T>
Examples
use chainerror::prelude::v1::*; use std::error::Error; use std::io; fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_context!(Func2Error); fn func2() -> Result<(), Box<dyn Error + Send + Sync>> { let filename = "foo.txt"; do_some_io().context(Func2Error(format!("Error reading '{}'", filename)))?; Ok(()) } #[derive(Debug)] enum Func1ErrorKind { Func2, IO(String), } /// impl ::std::fmt::Display for Func1ErrorKind {…} fn func1() -> ChainResult<(), Func1ErrorKind> { func2().context(Func1ErrorKind::Func2)?; do_some_io().context(Func1ErrorKind::IO("bar.txt".into()))?; Ok(()) } 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>>
fn downcast_inner_ref<T: 'static + Error>(&self) -> Option<&T>
[src]
fn downcast_inner_mut<T: 'static + Error>(&mut self) -> Option<&mut T>
[src]
impl<T: 'static + Display + Debug> Debug for ChainError<T>
[src]
impl<T: 'static + Display + Debug> Deref for ChainError<T>
[src]
impl<T: 'static + Display + Debug> Display for ChainError<T>
[src]
impl<T: 'static + Display + Debug> Error for ChainError<T>
[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
[src]
pub fn backtrace(&self) -> Option<&Backtrace>
[src]
pub fn description(&self) -> &str
1.0.0[src]
pub fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
impl<T: 'static + Display + Debug> Error for &mut ChainError<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for ChainError<T>
[src]
impl<T> Send for ChainError<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for ChainError<T> where
T: Sync,
[src]
T: Sync,
impl<T> Unpin for ChainError<T> where
T: Unpin,
[src]
T: Unpin,
impl<T> !UnwindSafe for ChainError<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> ChainErrorFrom<T> for U where
T: Into<U>,
U: 'static + Display + Debug,
[src]
T: Into<U>,
U: 'static + Display + Debug,
pub fn chain_error_from(T, Option<String>) -> ChainError<U>
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> IntoChainError<U> for T where
U: ChainErrorFrom<T>,
[src]
U: ChainErrorFrom<T>,
pub fn into_chain_error(Self, Option<String>) -> ChainError<U>
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,