track-error

Crates.iotrack-error
lib.rstrack-error
version0.1.0
created_at2025-08-22 11:45:45.548474+00
updated_at2025-08-22 11:45:45.548474+00
descriptionThis library provides serveral convenient macros to track the location of error where it first happened.
homepage
repositoryhttps://github.com/miaomiao1992/track-error
max_upload_size
id1806224
size9,561
杨学者 (miaomiao1992)

documentation

README

track-error

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

Requirements

  • Rust 2021

Usage

Add track-error as a dependency

[dependencies]
track-error = "0.1"

Since this crate just provides a easy and friendly wrapper for the error.

For example:

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);
    }
}
Commit count: 0

cargo fmt