#error #failure #track #tracking #object #mechanism #backtracing

trackable

This library provides a way to track objects manually as an alternative to mechanisms like backtracing

38 releases (4 stable)

Uses old Rust 2015

1.3.0 May 5, 2023
1.2.0 Apr 3, 2021
1.1.0 Mar 10, 2021
1.0.0 May 5, 2020
0.1.6 Mar 22, 2017

#68 in Debugging

Download history 14277/week @ 2023-11-21 18634/week @ 2023-11-28 20703/week @ 2023-12-05 21567/week @ 2023-12-12 17560/week @ 2023-12-19 9372/week @ 2023-12-26 24352/week @ 2024-01-02 26378/week @ 2024-01-09 24061/week @ 2024-01-16 33703/week @ 2024-01-23 42361/week @ 2024-01-30 31805/week @ 2024-02-06 38899/week @ 2024-02-13 43153/week @ 2024-02-20 53631/week @ 2024-02-27 46063/week @ 2024-03-05

186,874 downloads per month
Used in 130 crates (59 directly)

MIT license

48KB
801 lines

trackable

Crates.io: trackable Documentation Actions Status Coverage Status License: MIT

trackable provides functionalities to define trackable objects and track those.

Documentation

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

~1–1.4MB
~34K SLoC