pub struct ResourceBudget { /* private fields */ }Expand description
Represents resource budget.
Implementations§
Source§impl ResourceBudget
impl ResourceBudget
Sourcepub fn child(
&self,
name: impl Into<String>,
limit: BudgetLimit,
) -> Result<Self, RuntimeContractViolation>
pub fn child( &self, name: impl Into<String>, limit: BudgetLimit, ) -> Result<Self, RuntimeContractViolation>
Creates a child that inherits every dynamic ancestor’s admission state.
Creating a static child after closure is allowed; the resulting handle remains closed and cannot acquire or accept rebound permits.
§Errors
Returns a contract violation when the child name is blank or malformed, its limit is invalid, or its limit exceeds its parent.
Sourcepub fn register_dynamic_child(
&self,
name: impl Into<String>,
limit: BudgetLimit,
) -> Result<DynamicBudgetKey, DynamicKeyRegistrationFailure>
pub fn register_dynamic_child( &self, name: impl Into<String>, limit: BudgetLimit, ) -> Result<DynamicBudgetKey, DynamicKeyRegistrationFailure>
Registers a bounded dynamic child key under this budget.
The key owns a child budget and holds its name reserved until
DynamicBudgetKey::retire_until observes that the child has no
reservations left. A name that is already held cannot be registered
again, so a retired generation never runs beside the one that replaced
it. Use Self::child when the key does not need a retirement
lifecycle.
§Errors
Returns DynamicKeyRegistrationFailure when the child contract is
invalid, a dynamic ancestor has closed, the name is still held, or the
tree holds its maximum number of dynamic keys.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns whether a dynamic ancestor has permanently closed admission. Existing permits remain valid and can still be released or moved to an open budget.
Sourcepub fn try_acquire(
&self,
bytes: usize,
class: BudgetClass,
) -> Result<ResourcePermit, BudgetRejection>
pub fn try_acquire( &self, bytes: usize, class: BudgetClass, ) -> Result<ResourcePermit, BudgetRejection>
Attempts to acquire.
A BudgetRejection is a normal bounded outcome when the requested
capacity is unavailable; it is not an operational runtime failure.
Sourcepub fn try_acquire_data(
&self,
bytes: usize,
) -> Result<ResourcePermit, BudgetRejection>
pub fn try_acquire_data( &self, bytes: usize, ) -> Result<ResourcePermit, BudgetRejection>
Attempts to acquire data.
A BudgetRejection is a normal bounded outcome when data capacity is
unavailable; it is not an operational runtime failure.
Sourcepub fn try_acquire_control(
&self,
bytes: usize,
) -> Result<ResourcePermit, BudgetRejection>
pub fn try_acquire_control( &self, bytes: usize, ) -> Result<ResourcePermit, BudgetRejection>
Attempts to acquire control.
A BudgetRejection is a normal bounded outcome when control capacity
is unavailable; it is not an operational runtime failure.
Sourcepub fn snapshot(&self) -> BudgetSnapshot
pub fn snapshot(&self) -> BudgetSnapshot
Returns the snapshot.
Sourcepub fn limit(&self) -> BudgetLimit
pub fn limit(&self) -> BudgetLimit
Returns the limit.
Sourcepub fn monotonic_now(&self) -> Duration
pub fn monotonic_now(&self) -> Duration
Returns the current instant from this tree’s injected monotonic clock.
Sourcepub fn record_dropped(&self, count: usize)
pub fn record_dropped(&self, count: usize)
Records items discarded by a queue or custom retention boundary.
Sourcepub fn record_coalesced(&self, count: usize)
pub fn record_coalesced(&self, count: usize)
Records items folded into an already retained logical item.
Sourcepub fn record_slow_consumer_closed(&self)
pub fn record_slow_consumer_closed(&self)
Records a slow consumer closed by this budget’s full policy.