pub struct Budget { /* private fields */ }Expand description
The fuel of an evaluation attempt, on the request’s meter.
Fuel is normative (SPEC 15.12): the fuel of a cell’s evaluation is what its last,
completed attempt charges (used), whatever number of times the engine
restarted it. A request’s normative fuel is the sum of the evaluations it completes, and
its limit (limit) is checked at every charge against a lower bound of
that sum (each suspended evaluation will charge at least what its last attempt did), so a
request fails with BudgetExceeded exactly when its normative fuel exceeds the limit.
Separately the request’s work (every attempt, those discarded by a restart included,
and the engine’s validation reads) has a limit of its own, which bounds the total cost.
When either runs out, the request fails and stores nothing.
Implementations§
Source§impl Budget
impl Budget
Sourcepub fn new(fuel: u64) -> Budget
pub fn new(fuel: u64) -> Budget
A budget of fuel units, with no work limit (for a runtime’s own tests; the engine
makes the budget of a request from its configuration).
Sourcepub fn charge(&mut self, steps: u64) -> Result<(), EvalError>
pub fn charge(&mut self, steps: u64) -> Result<(), EvalError>
Charges steps units of work to this attempt. EvalError::BudgetExceeded when the
request’s fuel (or its work) runs out: the budget is then exhausted for the rest of the
request.
Sourcepub fn used(&self) -> u64
pub fn used(&self) -> u64
The fuel this attempt has charged so far: at the end of a completed attempt, the normative fuel of the evaluation.
Sourcepub fn remaining(&self) -> u64
pub fn remaining(&self) -> u64
The fuel left: the limit less the lower bound of the request’s normative fuel.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether a charge has failed.