pub struct ResourcePermit { /* private fields */ }Expand description
Represents resource permit.
The permit holds one count and its bytes of its class at every node of chain, the
chain of the budget it was acquired from or last rebound to, so a node needs no
reservation record of its own and the permit shares the budget’s chain instead of
holding each level.
Implementations§
Source§impl ResourcePermit
impl ResourcePermit
Sourcepub fn try_resize(&mut self, bytes: usize) -> Result<(), BudgetRejection>
pub fn try_resize(&mut self, bytes: usize) -> Result<(), BudgetRejection>
Changes the byte reservation without acquiring another count or rate token.
Growth reserves only the difference at each ancestor. A rejection rolls back every added byte and leaves this permit unchanged. Shrinking is allowed after budget closure; callers release the removed payload before shrinking its charge. This method does not block on available capacity.
§Errors
Returns a rejection if growth exceeds any ancestor’s byte limit or a dynamic ancestor has closed admission.
Sourcepub const fn class(&self) -> BudgetClass
pub const fn class(&self) -> BudgetClass
Returns the class.
Sourcepub fn promote_to_control(&mut self)
pub fn promote_to_control(&mut self)
Promotes a data reservation to the control class without releasing capacity.
The total count and byte ownership remain unchanged at every budget level. Data-only counters and rate tokens are released before a same-tree rebind can use control reserve.
Sourcepub fn try_rebind(
&mut self,
target: &ResourceBudget,
) -> Result<PermitBudgetTransferStatus, RuntimeContractViolation>
pub fn try_rebind( &mut self, target: &ResourceBudget, ) -> Result<PermitBudgetTransferStatus, RuntimeContractViolation>
Moves this reservation to another budget in the same resource tree.
Reservations for the common ancestor chain remain owned throughout the transfer. Target-only reservations are acquired before source-only reservations are released, so the payload is always covered without charging common ancestors twice.
Returns a normal rejection when the target is full. Contract failures and rejections leave this permit unchanged and valid for its source.
§Errors
Returns crate::RuntimeContractViolation::PermitTargetInDifferentTree
when target is outside this permit’s resource-budget tree.