trackable

Crates.iotrackable
lib.rstrackable
version1.3.0
sourcesrc
created_at2017-02-18 21:11:38.382144
updated_at2023-05-05 02:23:47.610971
descriptionThis library provides a way to track objects manually as an alternative to mechanisms like backtracing
homepagehttps://github.com/sile/trackable
repositoryhttps://github.com/sile/trackable
max_upload_size
id8574
size54,787
Takeru Ohta (sile)

documentation

README

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.

Commit count: 140

cargo fmt