[][src]Trait trackable::error::ErrorKindExt

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<F, K>(self, from: F) -> TrackableError<Self>
    where
        F: Into<TrackableError<K>>,
        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<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
"#);
}
Loading content...

Implementors

impl<T: ErrorKind> ErrorKindExt for T[src]

fn error(self) -> TrackableError<Self>[src]

fn cause<E>(self, cause: E) -> TrackableError<Self> where
    E: Into<BoxError>, 
[src]

fn takes_over<F, K>(self, from: F) -> TrackableError<Self> where
    F: Into<TrackableError<K>>,
    K: ErrorKind + Send + Sync + 'static, 
[src]

Loading content...