Crate trackable [] [src]

This crate provides functionalities to define trackable objects and track those.

Below is an example that tracks failure of an I/O operation:

#[macro_use]
extern crate trackable;

use trackable::error::{Failed, Failure, ErrorKindExt};

fn foo() -> Result<(), Failure> {
    track_try!(std::fs::File::open("/path/to/non_existent_file")
               .map_err(|e| Failed.cause(e)));
    Ok(())
}
fn bar() -> Result<(), Failure> {
    track_try!(foo());
    Ok(())
}
fn baz() -> Result<(), Failure> {
    track_try!(bar());
    Ok(())
}

fn main() {
    let result = baz();
    assert!(result.is_err());

    let error = result.err().unwrap();
    assert_eq!(format!("\r{}", error), r#"
Failed (cause; No such file or directory)
HISTORY:
  [0] at rust_out:<anon>:7
  [1] at rust_out:<anon>:12
  [2] at rust_out:<anon>:16
"#);
}

This example used the built-in Failure type, but you can easily define your own trackable error types. See the documentaion of error module for more details.

Modules

error

Functionalities for implementing trackable errors and operating on those.

Macros

track

Tries to track the current location into the history of the $target.

track_assert

Error trackable variant of the standard assert! macro.

track_assert_eq

Error trackable variant of the standard assert_ne! macro.

track_assert_ne

Error trackable variant of the standard assert_ne! macro.

track_err

Error tracking macro for the types which have map_err method.

track_panic

Error trackable variant of the standard panic! macro.

track_try

Error trackable variant of the standard try! macro.

Structs

History

The tracking history of a target.

Location

The location of interest in source code files.

TrackingNumber

Randomly generated tracking number.

Traits

Trackable

This trait allows to track an instance of an implementation type.