Skip to main content

Permit

Struct Permit 

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

Bytes reserved from a budget, returned when the permit drops.

A permit can take in another (Permit::absorb), so a buffer that grew past its first reservation carries every top-up in one owner, and can give back what its buffer no longer holds (Permit::shrink_to). Permits merge by home: an empty permit takes the home of the first one it absorbs, a permit of the same home adds its bytes, and one of another home merges into the record kept for that home, so a permit holds one record per distinct home whatever it absorbed (Self::records). Up to two distinct homes are stored inline, without heap allocation.

Implementations§

Source§

impl Permit

Source

pub fn detached(bytes: u64) -> Self

A permit that belongs to no budget.

Source

pub fn new(bytes: u64, home: Arc<dyn PermitHome>) -> Self

A permit that returns its bytes to home.

Source

pub fn bytes(&self) -> u64

The bytes this permit holds, absorbed permits included.

Source

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

Takes other in: its bytes are returned when this permit drops (merged by home, type docs). The first additional home stays inline.

Source

pub fn records(&self) -> usize

How many records this permit keeps besides its own: one per other home it absorbed. The first is inline and requires no allocation.

Source

pub fn shrink_to(&mut self, keep: u64)

Returns every byte above keep to its budget now.

Trait Implementations§

Source§

impl Debug for Permit

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Permit

§

impl !UnwindSafe for Permit

§

impl Forget for Permit

§

impl Freeze for Permit

§

impl Move for Permit

§

impl Send for Permit

§

impl Sync for Permit

§

impl Unpin for Permit

§

impl UnsafeUnpin for Permit

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.