Skip to main content

RunBudget

Struct RunBudget 

Source
pub struct RunBudget { /* private fields */ }
Expand description

The budget of one run: limits, and what was charged against them.

Implementations§

Source§

impl RunBudget

Source

pub fn unlimited() -> Self

A budget without limits that only counts, for node unit tests.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn remaining_tokens(&self) -> Option<u64>

Tokens left, None without a token limit.

Source

pub fn remaining_cost_micros(&self) -> Option<u64>

Cost left in micro units, None without a cost limit.

Source

pub fn is_limited(&self) -> bool

Whether the run has a token or a cost limit.

Source

pub fn state(&self) -> BudgetState

What the snapshot keeps: the counters and the limits.

Trait Implementations§

Source§

impl Debug for RunBudget

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for RunBudget

§

impl !RefUnwindSafe for RunBudget

§

impl !UnwindSafe for RunBudget

§

impl Forget for RunBudget

§

impl Move for RunBudget

§

impl Send for RunBudget
where Atomic<u64>: Send, BoxRaw<dyn Fn(String) + Sync + Send>: Send, Atomic<bool>: Send,

§

impl Sync for RunBudget
where Atomic<u64>: Sync, BoxRaw<dyn Fn(String) + Sync + Send>: Sync, Atomic<bool>: Sync,

§

impl Unpin for RunBudget
where Align8<u64>: Unpin, Box<dyn Fn(String) + Sync + Send>: Unpin, Align1<u8>: Unpin,

§

impl UnsafeUnpin for RunBudget
where Align8<u64>: UnsafeUnpin, *const dyn Fn(String) + Sync + Send is !null: UnsafeUnpin, PhantomData<dyn Fn(String) + Sync + Send>: UnsafeUnpin, Align1<u8>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.