pub struct RunBudget { /* private fields */ }Expand description
The budget of one run: limits, and what was charged against them.
Implementations§
Source§impl RunBudget
impl RunBudget
Sourcepub fn limited(max_tokens: Option<u64>, max_cost_micros: Option<u64>) -> Self
pub fn limited(max_tokens: Option<u64>, max_cost_micros: Option<u64>) -> Self
A budget with limits whose excess is only reported, for node unit tests.
Sourcepub fn charge(&self, usage: &Usage, cost_micros: u64) -> Result<(), NodeError>
pub fn charge(&self, usage: &Usage, cost_micros: u64) -> Result<(), NodeError>
Add usage (its total tokens) and cost_micros.
@throws NodeError - limit_exceeded (fatal) when a limit is passed. The
run stops then, so the error ends the node that charged.
Sourcepub fn record(&self, usage: &Usage, cost_micros: u64)
pub fn record(&self, usage: &Usage, cost_micros: u64)
Add usage and cost_micros without checking the limits: what the
last answer of a node cost when the node chose to answer within the
budget (it may pass the limit by that one answer, never more).
Sourcepub fn stop_if_spent(&self) -> Result<(), NodeError>
pub fn stop_if_spent(&self) -> Result<(), NodeError>
Stop the run when nothing is left of a limit, as a charge past it does.
@throws NodeError - limit_exceeded (fatal) when the budget is spent.
Sourcepub fn refuse(&self, why: String) -> NodeError
pub fn refuse(&self, why: String) -> NodeError
Stop the run for why (once), as a charge past a limit does: for a
node that finds the budget cannot afford its next call before making it.
Sourcepub fn remaining_tokens(&self) -> Option<u64>
pub fn remaining_tokens(&self) -> Option<u64>
Tokens left, None without a token limit.
Sourcepub fn remaining_cost_micros(&self) -> Option<u64>
pub fn remaining_cost_micros(&self) -> Option<u64>
Cost left in micro units, None without a cost limit.
Sourcepub fn is_limited(&self) -> bool
pub fn is_limited(&self) -> bool
Whether the run has a token or a cost limit.
Sourcepub fn state(&self) -> BudgetState
pub fn state(&self) -> BudgetState
What the snapshot keeps: the counters and the limits.