Expand description
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::Failure;
fn foo() -> Result<(), Failure> {
track!(std::fs::File::open("/path/to/non_existent_file").map_err(Failure::from_error))?;
Ok(())
}
fn bar() -> Result<(), Failure> {
track!(foo())?;
Ok(())
}
fn baz() -> Result<(), Failure> {
track!(bar())?;
Ok(())
}
fn main() {
let result = baz();
assert!(result.is_err());
let error = result.err().unwrap();
assert_eq!(format!("\r{}", error).replace('\\', "/"), r#"
Failed (cause; No such file or directory)
HISTORY:
[0] at src/lib.rs:7
[1] at src/lib.rs:12
[2] at src/lib.rs: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.
- result
- Trackable
Result
types for main and test functions.
Macros§
- derive_
traits_ for_ trackable_ error_ newtype Deprecated - Implements the typical traits for a newtype $error of
TrackableError<$kind>
. - track
- Tries to track the current location into the history of the
$target
. - track_
any_ err - The abbreviation of
track!($target.map_err(Failure::from_error), ..)
. - 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_
assert_ some - Trackable assertion for
Option
values. - track_
err - The abbreviation of
$target.map_err(|e| track!(e, ..))
. - track_
panic - Error trackable variant of the standard
panic!
macro. - track_
try_ unwrap - More human readable variant of the standard
Result::unwrap
method.
Structs§
Traits§
- Trackable
- This trait allows to track an instance of an implementation type.