Skip to main content

Track

Trait Track 

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

Attaches resource groups to a Future.

Provided Methods§

Source

fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>

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

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

§Examples
use resource_accounting::{ResourceGroupRegistry, ResourceGroupToken, Track as _};

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

let token = ResourceGroupRegistry::global().register_resource_group("my-group");
future
    .track_resources(token)
    .await
Source

fn in_current_resource_group(self) -> Tracked<Self>

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

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

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

§Examples
use resource_accounting::{ResourceGroupRegistry, ResourceGroupToken, Track as _};

let token = ResourceGroupRegistry::global().register_resource_group("my-group");
let _enter = token.enter();

// ...

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Sized> Track for T