Skip to main content

Crate track_error

Crate track_error 

Source
Expand description

This library provides a convenient macro and function to track the location of error where it first happened.

§Examples

§Add dependency

track-error = { version = "0.1"}

§How to use

use track_error::{Track, Tracked, track_error};

fn error_func() -> Result<(), String> {
    Err("something went wrong".to_string())
}

fn track_result() -> Result<(), Tracked<String>> {
    error_func().track()?;
    Ok(())
}

fn track_macro() -> Result<(), Tracked<String>> {
    let _ = error_func().map_err(|e| track_error!(e))?;
    Ok(())
}

fn main() {
    if let Err(e) = track_result() {
        println!("Error: {}", e);
        println!("Location: {}:{}", e.location().0, e.location().1);
    }
     
     if let Err(e) = track_macro() {
        println!("Error: {}", e);
        println!("Location: {}:{}", e.location().0, e.location().1);
    }
}

Macros§

track
track_error

Structs§

Tracked

Traits§

Track