Expand description
§Example
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);
}
}
fn main() {
My.foo();
}
Output
> CallContext { file: "main.rs", line: 13, fn_name: "bar" }
> CallContext { file: "main.rs", line: 20, fn_name: "baz" }
< CallContext { file: "main.rs", line: 20, fn_name: "baz" }
> CallContext { file: "main.rs", line: 20, fn_name: "baz" }
< CallContext { file: "main.rs", line: 20, fn_name: "baz" }
x + y = 30
< CallContext { file: "main.rs", line: 13, fn_name: "bar" }
< CallContext { file: "main.rs", line: 7, fn_name: "foo" }
Structs§
- Contains information about the current call site.
Traits§
- Tracing interface invoked by
#[trace]
and#[trace_with]
Attribute Macros§
- The
#[trace_with]
macro. Needs to be applied to function definitions, and will invoke hteTrace
interface on the user-provided expression.