func_trace

Crates.iofunc_trace
lib.rsfunc_trace
version1.0.3
sourcesrc
created_at2021-03-13 02:39:51.720258
updated_at2021-03-15 07:34:55.836141
descriptionA procedural macro for tracing the execution of functions
homepage
repositoryhttps://github.com/Larry850806/func_trace
max_upload_size
id368098
size45,738
Larry Lu (Larry850806)

documentation

README

trace Build Status Latest Version Documentation

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]
func_trace = "^1.0.3"

Example

use func_trace::trace;

func_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 {
    if a == 1 {
        2
    } else {
        b
    }
}

Output:

[+] Entering foo(a = 1, b = 2)
  [ENTER] Entering bar(a = 1, b = 2)
  [EXIT] Exiting bar = 2
[-] Exiting foo = ()
Commit count: 98

cargo fmt