pub trait MemoryReporter {
// Required method
fn heap_memory_bytes(&self) -> usize;
// Provided method
fn item_count(&self) -> usize { ... }
}Expand description
Trait for components that can report their memory usage.
Implementations should estimate heap memory owned by the component,
using capacity() * element_size for collections and size_of::<T>()
for fixed-size fields. The goal is a useful approximation, not an
exact byte count.
Required Methods§
Sourcefn heap_memory_bytes(&self) -> usize
fn heap_memory_bytes(&self) -> usize
Returns estimated heap memory usage in bytes.
This should include:
- Heap allocations owned by this component (Vec capacity, HashMap buckets, etc.)
- Nested heap allocations (String contents, Box contents)
This should NOT include:
- The size of
selfon the stack (the caller adds that if needed) - Memory owned by other components (avoid double-counting)
Provided Methods§
Sourcefn item_count(&self) -> usize
fn item_count(&self) -> usize
Returns the number of logical items stored.
For a hash map this might be len(), for an index the number of entries,
for a cache the number of cached items.