Skip to main content

Charge

Struct Charge 

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

Bytes charged to a Meter (and booked with its budget), returned when the charge drops. It rides inside whatever it paid for.

Bookkeeping. A charge holds one Permit for its own meter, and every charge it absorbs from that meter merges into it (bytes added, permits merged by home), so a value built from any number of charged tables keeps one record, however its budget books it. A charge absorbed from another meter is kept as one record per distinct meter. Neither grows with the input: one meter and one budget home (every budget of the core: Unbounded, crate::budget::Counting) allocate no record at all (tests/memory_model.rs checks this under Counting).

Implementations§

Source§

impl Charge

Source

pub fn zero(meter: &Arc<Meter>) -> Self

A charge of nothing on meter, to grow.

Source

pub fn bytes(&self) -> u64

The bytes held, absorbed charges included.

Source

pub fn meter(&self) -> &Arc<Meter> ⓘ

The meter this charge is on.

Source

pub fn grow(&mut self, bytes: u64) -> Result<(), ChargeError>

Charges bytes more to the same meter. A refusal changes nothing.

Source

pub fn release(&mut self, bytes: u64)

Returns up to bytes of this meter’s part now (what a buffer no longer holds).

Source

pub fn absorb(&mut self, other: Charge)

Takes other in: its bytes are returned when this charge drops. A charge of this meter merges into this one; a charge of another meter merges into the record this charge keeps for that meter (type docs).

Source

pub fn records(&self) -> usize

How many records this charge keeps besides its own: one per other meter it absorbed, plus its permit’s (Permit::records).

Trait Implementations§

Source§

impl Debug for Charge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Charge

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Charge

§

impl !UnwindSafe for Charge

§

impl Forget for Charge

§

impl Freeze for Charge

§

impl Move for Charge

§

impl Send for Charge

§

impl Sync for Charge

§

impl Unpin for Charge

§

impl UnsafeUnpin for Charge

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> Same for T

Source§

type Output = T

Should always be Self
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.