pub struct Budget { /* private fields */ }Expand description
An allowance being drawn down by one operation and everything nested inside it.
Cloning shares the same counters rather than copying them, which is the property that makes limits compose: an operation that calls another passes a clone, and the two draw from one pool. A budget that reset per subsystem would bound each step and nothing overall, which is what having several unrelated local limits already achieved.
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn new(limits: ResourceLimits) -> Self
pub fn new(limits: ResourceLimits) -> Self
A fresh budget against limits.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
A fresh budget against ResourceLimits::defaults.
Sourcepub const fn limits(&self) -> &ResourceLimits
pub const fn limits(&self) -> &ResourceLimits
The limits this budget draws against.
Sourcepub fn charge(
&self,
resource: Resource,
amount: u64,
) -> Result<(), LimitExceeded>
pub fn charge( &self, resource: Resource, amount: u64, ) -> Result<(), LimitExceeded>
Charge amount against resource.
§Errors
Returns LimitExceeded naming resource and its bound when
the charge would take the total past it. The amount is still
recorded, so a caller that ignores one failure and continues
does not find the next charge succeeding.
Sourcepub const fn enter(&self, level: u64) -> Result<(), LimitExceeded>
pub const fn enter(&self, level: u64) -> Result<(), LimitExceeded>
Check that level is within the depth bound.
§Errors
Returns LimitExceeded for Resource::Depth when level
is past the bound.