track_var_smart

Macro track_var_smart 

Source
macro_rules! track_var_smart {
    ($var:expr) => { ... };
}
Expand description

[SMART] Intelligent tracking that automatically chooses the best strategy.

This macro automatically detects the variable type and chooses the optimal tracking approach:

  • For Copy types (i32, f64, bool, etc.): Creates a copy for tracking (zero overhead)
  • For non-Copy types: Uses reference-based tracking like track_var!
  • For smart pointers (Rc, Arc): Clones the pointer (cheap reference increment)

§✅ Use this when:

  • You want the best of both worlds without thinking about it
  • You’re tracking mixed types (some Copy, some not)
  • You want automatic optimization based on type characteristics
  • You’re prototyping and want convenience

§❌ Don’t use this when:

  • You need explicit control over tracking behavior
  • You’re in performance-critical code and want predictable behavior
  • You need precise lifecycle tracking (use track_var_owned! instead)

§Example

use memscope_rs::track_var_smart;

let number = 42i32;           // Copy type - will be copied
let my_vec = vec![1, 2, 3];   // Non-Copy - will be tracked by reference
let rc_data = Rc::new(vec![]); // Smart pointer - will clone the Rc

track_var_smart!(number);   // Copies the i32 (cheap)
track_var_smart!(my_vec);    // Tracks by reference (zero cost)
track_var_smart!(rc_data);   // Clones Rc (cheap reference increment)

// All variables remain fully usable!
println!("{}, {:?}, {:?}", number, my_vec, rc_data);