pub struct Context { /* private fields */ }Expand description
The context of a size query, used to keep track of shared pointers and the aggregated totals of seen data
Implementations§
Source§impl Context
impl Context
Returns true if the current context is shared
Run the given closure and mark all added allocations as shared
Sourcepub fn add_distinct_allocation(&mut self) -> &mut Self
pub fn add_distinct_allocation(&mut self) -> &mut Self
Adds one distinct allocation to the current context
Sourcepub fn add_distinct_allocations(&mut self, allocations: usize) -> &mut Self
pub fn add_distinct_allocations(&mut self, allocations: usize) -> &mut Self
Adds allocations distinct allocations to the current context
Sourcepub fn add(&mut self, size: usize) -> &mut Self
pub fn add(&mut self, size: usize) -> &mut Self
Adds size to the total bytes
- Adds
sizeto the shared bytes if the context is currently shared
Adds size shared bytes
Sourcepub fn add_excess(&mut self, size: usize) -> &mut Self
pub fn add_excess(&mut self, size: usize) -> &mut Self
Adds size to the total and excess bytes
- Adds
sizeto the shared bytes if the context is currently shared
Sourcepub fn add_arraylike(&mut self, len: usize, element_size: usize) -> &mut Self
pub fn add_arraylike(&mut self, len: usize, element_size: usize) -> &mut Self
Adds a vector-like object to the current context.
- Adds
len * element_sizeto the total bytes - Adds
len * element_sizeto the shared bytes if the context is currently shared
Sourcepub fn add_vectorlike(
&mut self,
len: usize,
capacity: usize,
element_size: usize,
) -> &mut Self
pub fn add_vectorlike( &mut self, len: usize, capacity: usize, element_size: usize, ) -> &mut Self
Adds a vector-like object to the current context.
- Adds
capacity * element_sizeto the total bytes - Adds
(capacity - len) * element_sizeto the excess bytes - Adds
capacity * element_sizeto the shared bytes if the context is currently shared
Sourcepub fn insert_ptr<T: ?Sized>(&mut self, ptr: *const T) -> bool
pub fn insert_ptr<T: ?Sized>(&mut self, ptr: *const T) -> bool
Returns true and adds the given pointer to the current context if it
hasn’t seen it yet. Returns false if the current context has seen the
pointer before
Sourcepub fn add_ptr<T: ?Sized>(&mut self, ptr: *const T) -> &mut Self
pub fn add_ptr<T: ?Sized>(&mut self, ptr: *const T) -> &mut Self
Adds the given pointer to the current context regardless of whether it’s seen it yet
Sourcepub fn contains_ptr<T: ?Sized>(&self, ptr: *const T) -> bool
pub fn contains_ptr<T: ?Sized>(&self, ptr: *const T) -> bool
Returns true if the context has seen the given pointer
Sourcepub const fn total_size(&self) -> TotalSize
pub const fn total_size(&self) -> TotalSize
Returns the total size of all objects the current context has seen
Trait Implementations§
Source§impl SizeOf for Context
impl SizeOf for Context
Source§fn size_of_children(&self, context: &mut Context)
fn size_of_children(&self, context: &mut Context)
Source§fn size_of_with_context(&self, context: &mut Context)
fn size_of_with_context(&self, context: &mut Context)
Context,
including both the size of the value itself and all of its children