Trait trackable::error::ErrorKindExt
[−]
[src]
pub trait ErrorKindExt: ErrorKind + Sized { fn error(self) -> TrackableError<Self> { ... } fn cause<E>(self, cause: E) -> TrackableError<Self> where E: Into<BoxError> { ... } fn takes_over<K>(self, from: TrackableError<K>) -> TrackableError<Self> where K: ErrorKind + Send + Sync + 'static { ... } }
An extention of ErrorKind
trait.
This provides convenient functions to create a TrackableError
instance of this kind.
Provided Methods
fn error(self) -> TrackableError<Self>
Makes a TrackableError
instance without cause.
Examples
use std::error::Error; use trackable::error::{Failed, ErrorKindExt}; let e = Failed.error(); assert!(e.cause().is_none());
fn cause<E>(self, cause: E) -> TrackableError<Self> where E: Into<BoxError>
Makes a TrackableError
instance with the specified cause
.
Examples
use std::error::Error; use trackable::error::{Failed, ErrorKindExt}; let e = Failed.cause("something wrong"); assert_eq!(e.cause().unwrap().to_string(), "something wrong");
fn takes_over<K>(self, from: TrackableError<K>) -> TrackableError<Self> where K: ErrorKind + Send + Sync + 'static
Takes over from other TrackableError
instance.
If either from.in_tracking()
or self.is_tracking_needed()
is true
,
tracking of the returning TrackableError
will be enabled.
The history of from
will be preserved.
Examples
use trackable::error::{ErrorKind, ErrorKindExt}; #[derive(Debug)] struct Kind0; impl ErrorKind for Kind0 {} #[derive(Debug)] struct Kind1; impl ErrorKind for Kind1 {} fn main() { let e = Kind0.error(); let e = track!(e); let e = Kind1.takes_over(e); let e = track!(e); assert_eq!(format!("\nERROR: {}", e), r#" ERROR: Kind1 HISTORY: [0] at <anon>:16 [1] takes over from `Kind0` [2] at <anon>:19 "#); }
Implementors
impl<T: ErrorKind> ErrorKindExt for T