pub trait MemoryBudget:
Send
+ Sync
+ Debug {
// Required method
fn try_reserve(
&self,
bytes: u64,
what: Reservation,
) -> Result<Permit, BudgetExceeded>;
// Provided method
fn allocator_refused(&self, _error: AllocError) { ... }
}Expand description
A source of permits.
Contract (plan section 3.16). The core calls a budget, and a permit’s
home, wherever it charges or returns memory, including while it holds
one of its own locks (publishing a decoded run grows the bundle’s run
table under its mutex; a value replaced in a cell or a registry slot
returns its charge as it drops). So an implementation must not block (it
refuses instead: blocking inside a pool can deadlock it), must not call
into the core, and must not take a lock that a thread may hold while it
calls the core (Python’s GIL among them): a budget that does any of these
can deadlock against a core lock. Unbounded and Counting are
atomic counters. The permits of one pool share one home (one
Arc<dyn PermitHome>): the core merges permits by home, and keeps one
record per distinct home a charge absorbs, so a budget that made a home
per reservation would grow every owner’s bookkeeping.
Required Methods§
Sourcefn try_reserve(
&self,
bytes: u64,
what: Reservation,
) -> Result<Permit, BudgetExceeded>
fn try_reserve( &self, bytes: u64, what: Reservation, ) -> Result<Permit, BudgetExceeded>
Reserves bytes, or refuses at once. A successful permit holds exactly
bytes, including when detached from any home.
Provided Methods§
Sourcefn allocator_refused(&self, _error: AllocError)
fn allocator_refused(&self, _error: AllocError)
Observes a detected allocator refusal exactly once at its source. Wrapping or cloning the error must not notify again. Optional work may absorb it, including settle after a successful registry commit; a batch caller must audit observations before continuing or publishing.
The same nonblocking, non-reentrant contract as budget operations applies. Implementations must also allocate nothing while reporting a refusal.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".