Trait trackable::error::ErrorKindExt
source · pub trait ErrorKindExt: ErrorKind + Sized {
// Provided methods
fn error(self) -> TrackableError<Self> { ... }
fn cause<E>(self, cause: E) -> TrackableError<Self>
where E: Into<BoxError> { ... }
fn takes_over<F, K>(self, from: F) -> TrackableError<Self>
where F: Into<TrackableError<K>>,
K: ErrorKind + Send + Sync + 'static { ... }
}
Expand description
An extention of ErrorKind
trait.
This provides convenient functions to create a TrackableError
instance of this kind.
Provided Methods§
sourcefn error(self) -> TrackableError<Self>
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());
sourcefn cause<E>(self, cause: E) -> TrackableError<Self>where
E: Into<BoxError>,
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");
Examples found in repository?
examples/your_own_error_type_template.rs (line 16)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn from(f: std::io::Error) -> Self {
ErrorKind::Other.cause(f).into()
}
}
#[derive(Debug, Clone)]
pub enum ErrorKind {
Other,
}
impl TrackableErrorKind for ErrorKind {}
fn main() {
let e = ErrorKind::Other.cause("something wrong");
let e = track!(e);
let e = track!(e);
println!("Error: {}", e);
}
sourcefn takes_over<F, K>(self, from: F) -> TrackableError<Self>where
F: Into<TrackableError<K>>,
K: ErrorKind + Send + Sync + 'static,
fn takes_over<F, K>(self, from: F) -> TrackableError<Self>where F: Into<TrackableError<K>>, K: ErrorKind + Send + Sync + 'static,
Takes over from other TrackableError
instance.
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).replace('\\', "/"), r#"
ERROR: Kind1
HISTORY:
[0] at src/error.rs:17
[1] at src/error.rs:20
"#);
}