call-trace 0.4.0

Provides a way to annotate a function to inject tracing code before and after its body.
Documentation
use call_trace::{trace_with, CallContext, Trace};

struct My;

impl My {
    #[inline]
    #[trace_with(self)]
    /// test
    fn foo(&mut self) {
        self.bar();
    }

    #[trace_with(self)]
    fn bar(&mut self) {
        let x = self.baz();
        let y = self.baz();
        println!("x + y = {}", x + y);
    }

    #[trace_with(self)]
    fn baz(&mut self) -> i32 {
        15
    }
}

impl Trace for My {
    fn on_pre(&mut self, ctx: &CallContext) {
        println!("> {:?}", ctx);
    }
    fn on_post(&mut self, ctx: &CallContext) {
        println!("< {:?}", ctx);
    }
}

#[test]
fn test() {
    My.foo();
}