gsingh93/trace


A Rust procedural macro for tracing function execution

License: MIT

Language: Rust


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 = ()

Project Statistics

Sourcerank 7
Repository Size 70.3 KB
Stars 311
Forks 31
Watchers 10
Open issues 3
Dependencies 10
Contributors 14
Tags 0
Created
Last updated
Last pushed

Top Contributors See all

Gulshan Singh hcpl gsingh2011 Yohaï-Eliel Berreby varding Michael Rosenberg Rob Day Pierre Chanquion gmorenz Bruno Bigras Jon Haggblad Larry Lu max Maciej Dziardziel

Packages Referencing this Repo

pollard-p-minus-one
An implementation of Pollard's p-1 factoring algorithm
Latest release 0.1.0 - Published - 311 stars
trace
A procedural macro for tracing the execution of functions
Latest release 0.1.7 - Updated - 311 stars

Interesting Forks See all

bumzack/trace
A Rust syntax extension for tracing function execution
Rust - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2022-12-27 23:40:09 UTC

Login to resync this repository