Skip to main content

BytePermits

Trait BytePermits 

Source
pub trait BytePermits: Send + Sync {
    // Required method
    async fn acquire(&self, n_bytes: usize) -> Permit;
}
Expand description

Backpressure permit trait.

Implementations control write pump flow based on byte counts.

Native async-fn-in-trait rather than #[async_trait]: acquire is on the per-write flow-control path, so the box-per-call async_trait added was pure overhead. The trait is used behind generics, never as dyn BytePermits.

Required Methods§

Source

async fn acquire(&self, n_bytes: usize) -> Permit

Acquire permission to write n_bytes.

This may suspend (on the executor, never on a blocking thread) if the system is under memory pressure, resuming when enough capacity frees up.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§