track_new_guard

Function track_new_guard 

Source
pub fn track_new_guard<T>(name: &'static str, value: T) -> TrackGuard<T>
Expand description

Track a new variable with automatic drop tracking.

Returns a TrackGuard that automatically calls track_drop when it goes out of scope.

§Arguments

  • name - A static string name for the variable (must be 'static for the guard)
  • value - The value to track

§Returns

A TrackGuard<T> that derefs to T and tracks drop automatically.

§Example

fn example() {
    let data = track_new_guard("data", vec![1, 2, 3]);
    let sum: i32 = data.iter().sum();
    println!("Sum: {}", sum);
    // track_drop("data") called automatically here
}

example();
let events = get_events();
assert!(events[0].is_new());
assert!(events[1].is_drop());