pub trait MallocSizeOf {
    fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize;

    fn constant_size() -> Option<usize>
   where
        Self: Sized
, { ... } }
Expand description

Trait for measuring the “deep” heap usage of a data structure. This is the most commonly-used of the traits.

Required Methods

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself. If T::size_of is a constant, consider implementing constant_size as well.

Provided Methods

Used to optimize MallocSizeOf implementation for collections like Vec and HashMap to avoid iterating over them unnecessarily. The Self: Sized bound is for object safety.

Implementations on Foreign Types

If a mutex is stored directly as a member of a data type that is being measured, it is the unique owner of its contents and deserves to be measured.

If a mutex is stored inside of an Arc value as a member of a data type that is being measured, the Arc will not be automatically measured so there is no risk of overcounting the mutex’s contents.

The same reasoning applies to RwLock.

Implementors