12 releases

0.1.7 Dec 27, 2022
0.1.6 Oct 22, 2020
0.1.5 Apr 16, 2020
0.1.4 Mar 7, 2018
0.0.4 Apr 22, 2015

#856 in Procedural macros

Download history 3266/week @ 2023-12-07 2928/week @ 2023-12-14 2221/week @ 2023-12-21 1543/week @ 2023-12-28 2542/week @ 2024-01-04 2763/week @ 2024-01-11 3063/week @ 2024-01-18 2652/week @ 2024-01-25 2585/week @ 2024-02-01 2479/week @ 2024-02-08 3421/week @ 2024-02-15 3969/week @ 2024-02-22 3201/week @ 2024-02-29 3258/week @ 2024-03-07 3298/week @ 2024-03-14 2285/week @ 2024-03-21

12,708 downloads per month
Used in 3 crates

MIT license

32KB
566 lines

trace

Unit tests Latest Version Documentation License

A procedural macro for tracing the execution of functions.

Adding #[trace] to the top of functions, mods, or impls will insert println! statements at the beginning and the end of the affected functions, notifying you of when that function was entered and exited and printing the argument and return values. Useful for quickly debugging whether functions that are supposed to be called are actually called without manually inserting print statements.

See the examples directory and the documentation for more detail on how to use and configure this library.

Installation

Add it as a dependency in your Cargo.toml file:

[dependencies]
trace = "*"

Example

use trace::trace;

trace::init_depth_var!();

fn main() {
    foo(1, 2);
}

#[trace]
fn foo(a: i32, b: i32) {
    println!("I'm in foo!");
    bar((a, b));
}

#[trace(prefix_enter="[ENTER]", prefix_exit="[EXIT]")]
fn bar((a, b): (i32, i32)) -> i32 {
    println!("I'm in bar!");
    if a == 1 {
        2
    } else {
        b
    }
}

Output:

[+] Entering foo(a = 1, b = 2)
I'm in foo!
 [ENTER] Entering bar(a = 1, b = 2)
I'm in bar!
 [EXIT] Exiting bar = 2
[-] Exiting foo = ()

Dependencies

~1.5MB
~33K SLoC