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

#229 in Procedural macros

Download history 2806/week @ 2024-06-19 3723/week @ 2024-06-26 2157/week @ 2024-07-03 2088/week @ 2024-07-10 910/week @ 2024-07-17 1271/week @ 2024-07-24 1776/week @ 2024-07-31 1611/week @ 2024-08-07 942/week @ 2024-08-14 968/week @ 2024-08-21 818/week @ 2024-08-28 767/week @ 2024-09-04 842/week @ 2024-09-11 988/week @ 2024-09-18 650/week @ 2024-09-25 661/week @ 2024-10-02

3,336 downloads per month
Used in 6 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
~35K SLoC