Struct Context

Source
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

Source

pub fn new() -> Self

Creates a new, empty context

Source

pub const fn is_shared(&self) -> bool

Returns true if the current context is shared

Source

pub fn shared<F>(&mut self, with_shared: F) -> &mut Self
where F: FnOnce(&mut Self),

Run the given closure and mark all added allocations as shared

Source

pub fn add_distinct_allocation(&mut self) -> &mut Self

Adds one distinct allocation to the current context

Source

pub fn add_distinct_allocations(&mut self, allocations: usize) -> &mut Self

Adds allocations distinct allocations to the current context

Source

pub fn add(&mut self, size: usize) -> &mut Self

Adds size to the total bytes

  • Adds size to the shared bytes if the context is currently shared
Source

pub fn add_shared(&mut self, size: usize) -> &mut Self

Adds size shared bytes

Source

pub fn add_excess(&mut self, size: usize) -> &mut Self

Adds size to the total and excess bytes

  • Adds size to the shared bytes if the context is currently shared
Source

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_size to the total bytes
  • Adds len * element_size to the shared bytes if the context is currently shared
Source

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_size to the total bytes
  • Adds (capacity - len) * element_size to the excess bytes
  • Adds capacity * element_size to the shared bytes if the context is currently shared
Source

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

Source

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

Source

pub fn contains_ptr<T: ?Sized>(&self, ptr: *const T) -> bool

Returns true if the context has seen the given pointer

Source

pub const fn total_size(&self) -> TotalSize

Returns the total size of all objects the current context has seen

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Context

Source§

fn default() -> Context

Returns the “default value” for a type. Read more
Source§

impl SizeOf for Context

Source§

fn size_of_children(&self, context: &mut Context)

Gets the size of all “children” owned by this value, not including the size of the value itself. Read more
Source§

fn size_of(&self) -> TotalSize

Gets the total size of the current value
Source§

fn size_of_with_context(&self, context: &mut Context)

Adds the size of the current value to the given Context, including both the size of the value itself and all of its children

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.