Skip to main content

Ledger

Struct Ledger 

Source
pub struct Ledger { /* private fields */ }
Expand description

The aggregate heap and charges of the registered threads, observed at each event. cost is the charge unit of a block’s size (the core’s heap_cost, which the testkit does not link): a test passes it.

Implementations§

Source§

impl Ledger

Source

pub const fn new(cost: fn(u64) -> u64) -> Self

An empty ledger whose blocks cost cost(size).

Source

pub fn arm(&self, allowance: u64) -> (i64, i64)

Starts a measured window: from now each event’s residual, the heap’s rise since now less the charges’, is held against allowance, the uncharged bytes the window may hold, and the peaks and the first violation start again. The live heap and charges are not reset. Returns the coherent (heap, charged) at the arm for phase-local absolute residual comparisons.

Source

pub fn charge(&self, bytes: u64)

A budget granted bytes: held from this event on.

Source

pub fn release(&self, bytes: u64)

A held charge of bytes was returned.

Source

pub fn observe(&self) -> Observation

The state now, read inside the critical section: one instant.

Trait Implementations§

Source§

impl Tally for Ledger

Counted conservatively: a block is counted before System is asked for it and uncounted once System has freed it, so the ledger’s heap is never below the live heap, whatever the threads’ interleaving; a moving realloc counts its new block before the call and drops its old one after success; a failed request is rolled back. A nonmoving shrink holds the old cost through the call, then replaces it in one event.

Source§

fn grew(&self, _size: usize, _zeroed: bool)

Counted already, by Self::growing.

Source§

fn shrunk(&self, old: usize, new: usize)

Replace an old block after a successful in-place shrink. There was no provisional new block; coherent tallies update in one event.
Source§

fn growing(&self, size: usize)

A block of size bytes is about to be asked of System on a counted thread (a fresh block, or a realloc’s new one): told before it can be live, so a tally that counts here never holds less than the live heap. Nothing, by default.
Source§

fn failed(&self, size: usize)

The request Self::growing told of failed: no block was made. Nothing, by default.
Source§

fn shrank(&self, size: usize)

A block of size bytes was freed on a counted thread: told once System has freed it.
Source§

fn refuses(&self, size: usize) -> bool

Whether a request of size bytes fails without reaching System, on any thread (a test that refuses huge requests rather than meet the machine’s limit). Never, by default.
Source§

fn refuses_realloc(&self, new_size: usize) -> bool

Whether a realloc to new_size bytes fails without reaching System: Self::refuses, by default. A test that refuses one fresh allocation of a size, and never a growth or shrink the code under test makes infallibly, answers false here.

Auto Trait Implementations§

§

impl !Freeze for Ledger

§

impl Forget for Ledger

§

impl Move for Ledger

§

impl RefUnwindSafe for Ledger

§

impl Send for Ledger

§

impl Sync for Ledger

§

impl Unpin for Ledger

§

impl UnsafeUnpin for Ledger

§

impl UnwindSafe for Ledger

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, 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.