Struct AllocationGroupToken

Source
pub struct AllocationGroupToken(/* private fields */);
Expand description

A token that allows controlling when an allocation group is active or inactive.

Allocation groups represent the core mechanism for categorizing allocation activity, where the group must be active for (de)allocation events to be attributed to it. Practically speaking, allocation groups are simply an internal identifier that is used to identify the “owner” of an allocation.

§Usage

In order for an allocation group to be attached to an allocation, it must be “entered.” AllocationGroupToken functions similarly to something like a mutex, where “entering” the token conumes the token and provides a guard: AllocationGuard. This guard is tied to the allocation group being active: if the guard is dropped, or if it is exited manually, the allocation group is no longer active.

AllocationGuard also tracks if another allocation group was active prior to entering, and ensures it is set back as the active allocation group when the guard is dropped. This allows allocation groups to be nested within each other.

Implementations§

Source§

impl AllocationGroupToken

Source

pub fn register() -> Option<AllocationGroupToken>

Registers an allocation group token.

Allocation groups use an internal identifier that is incremented atomically, and monotonically, when registration occurs. This identifier, thus, has a limit based on the pointer size of the architecture. In other words, on 32-bit systems, a limit of 2^32 allocation groups can be registered before this identifier space is exhausted. On 64-bit systems, this limit is 2^64.

If the number of registered allocation groups exceeds the limit, None is returned. This is a permanent state until the application exits. Otherwise, Some is returned.

Source

pub fn id(&self) -> AllocationGroupId

Gets the ID associated with this allocation group.

Source

pub fn enter(&mut self) -> AllocationGuard<'_>

Enters the allocation group, marking it as the active allocation group on this thread.

If another allocation group is currently active, it is replaced, and restored either when this allocation guard is dropped, or when AllocationGuard::exit is called.

Source§

impl AllocationGroupToken

Source

pub fn attach_to_span(self, span: &Span)

Available on crate feature tracing-compat only.

Attaches this allocation group to a tracing Span.

When the span is entered or exited, the allocation group will also transition from inactive to active, and vise versa. In effect, all allocations that occur while the span is entered will be associated with the allocation group.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more