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
impl Permit
Sourcepub fn new(bytes: u64, home: Arc<dyn PermitHome>) -> Self
pub fn new(bytes: u64, home: Arc<dyn PermitHome>) -> Self
A permit that returns its bytes to home.
Sourcepub fn absorb(&mut self, other: Permit)
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.