Track

Trait Track 

Source
pub trait Track: Sized {
    // Provided methods
    fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>  { ... }
    fn in_current_allocation_group(self) -> Tracked<Self>  { ... }
}
Expand description

Attaches allocation groups to a Future.

Provided Methods§

Source

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper.

The allocation group will be entered every time the wrapped future is polled.

§Examples
use memory_accounting::allocator::{AllocationGroupRegistry, AllocationGroupToken, Track as _};

let future = async {
    // All allocations in this future will be attached to the allocation group
    // represented by `token`...
};

let token = AllocationGroupRegistry::global().register_allocation_group("my-group");
future
    .track_allocations(token)
    .await
Source

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper.

The allocation group will be entered every time the wrapped future is polled.

This can be used to propagate the current allocation group when spawning a new future.

§Examples
use memory_accounting::allocator::{AllocationGroupRegistry, AllocationGroupToken, Track as _};

let token = AllocationGroupRegistry::global().register_allocation_group("my-group");
let _enter = token.enter();

// ...

let future = async {
    // All allocations in this future will be attached to the allocation group
    // represented by `token`...
};
tokio::spawn(future.in_current_allocation_group());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Sized> Track for T