pub trait MemoryUsage {
// Required method
fn memory_usage(&self) -> usize;
// Provided methods
fn memory_usage_compacted(&self) -> usize { ... }
fn compact_memory(&mut self) -> usize { ... }
fn memory_usage_compacted_ref(&self) -> usize { ... }
fn compact_memory_ref(&self) -> usize { ... }
}Expand description
Types that know their own memory usage
Required Methods§
Sourcefn memory_usage(&self) -> usize
fn memory_usage(&self) -> usize
Get memory usage (including direct, indirect, and compactible memory)
Provided Methods§
Sourcefn memory_usage_compacted(&self) -> usize
fn memory_usage_compacted(&self) -> usize
Get expected memory usage after compaction
Compaction means to remove unnecessary memory usage. This would include,
for example, removing the unused capacity of a [Vec], by calling
shrink_to_fit().
Types like [Vec] that support memory compaction should reimplement
this function.
Sourcefn compact_memory(&mut self) -> usize
fn compact_memory(&mut self) -> usize
Perform memory compaction, saving as much memory as possible, returning the amount of bytes saved
Sourcefn memory_usage_compacted_ref(&self) -> usize
fn memory_usage_compacted_ref(&self) -> usize
Get expected memory usage after compaction behind a shared reference
This is useful for types with interior mutability. Types that have or
could have (ie. with generics) should implement this method and
compact_memory_ref().
For types that don’t, the default implementation is a no-op.
See MemoryUsage::memory_usage_compacted for more details.
Sourcefn compact_memory_ref(&self) -> usize
fn compact_memory_ref(&self) -> usize
Perform memory compaction behind a shared reference, saving as much memory as possible, returning the amount of bytes saved
This is useful for types with interior mutability. Types that have or
could have (ie. with generics) should implement this method and
memory_usage_compacted_ref().
For types that don’t, the default implementation is a no-op.
See MemoryUsage::compact_memory for more details.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".