Skip to main content

Trackable

Derive Macro Trackable 

Source
#[derive(Trackable)]
Expand description

Derive macro for automatically implementing the Trackable trait.

This macro generates implementations for:

  • get_heap_ptr(): Returns the struct’s address for structs with heap allocations
  • get_type_name(): Returns the type name as a string literal
  • get_size_estimate(): Calculates total size including internal allocations
  • get_internal_allocations(): Lists all internal heap allocations

§Examples

use memscope_rs::Trackable;
use memscope_derive::Trackable;

#[derive(Trackable)]
struct UserData {
    name: String,
    scores: Vec<i32>,
    metadata: Box<HashMap<String, String>>,
}

The macro handles:

  • Structs with named fields
  • Tuple structs
  • Unit structs
  • Enums with data
  • Nested types that implement Trackable