37 releases (3 stable)
Uses old Rust 2015
1.2.0 | Apr 3, 2021 |
---|---|
1.1.0 | Mar 10, 2021 |
1.0.0 | May 5, 2020 |
0.2.24 | Mar 14, 2021 |
0.1.6 | Mar 22, 2017 |
#68 in Debugging
30,208 downloads per month
Used in less than 60 crates
47KB
801 lines
trackable
trackable
provides functionalities to define trackable objects and track those.
Below code 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), 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.
Dependencies
~0.4–0.9MB
~21K SLoC