Skip to main content

QuotaToken

Struct QuotaToken 

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

An unforgeable capability granting the right to consume a named resource.

Dropping the token releases the underlying lease back to the executor pool.

§Example

let token = QuotaToken::new("llm-tokens", 1000);
match token.reserve(500) {
    Ok(reservation) => {
        let used = call_llm_api();
        reservation.commit(used);
    }
    Err(e) => eprintln!("quota unavailable: {e}"),
}

Implementations§

Source§

impl QuotaToken

Source

pub fn new(resource_name: &str, expected_use: u64) -> Self

Request a quota capability for the given resource.

  • resource_name: the resource name as declared in the manifest.
  • expected_use: expected units per reservation; used to derive the credit rate and max-credit for fair scheduling.
Source

pub fn reserve(&self, amount: u64) -> Result<Reservation, FailedReservation>

Reserve amount units from the local allocation.

Blocks internally until capacity is available or the resource’s enforcement action fires. Returns a Reservation handle that must be committed (or dropped) to release unused capacity.

Returns Err(FailedReservation) when the enforcement policy is reject. For throttle / terminate policies the call suspends or terminates the agent before returning.

Source

pub fn split(&mut self, child_expected_use: u64) -> QuotaToken

Split off a child token with child_expected_use units.

  • The parent’s expected-use is reduced by child_expected_use.
  • Credits are divided proportionally between parent and child.
§Panics

Traps if child_expected_use exceeds the parent’s current expected-use.

Source

pub fn merge(&mut self, other: QuotaToken)

Merge other into this token, combining expected-use and credits.

Both tokens must refer to the same resource (same resource-name and environment). other is consumed.

§Panics

Traps if the tokens refer to different resources.

Trait Implementations§

Auto Trait Implementations§

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> IntoValueAndType for T
where T: IntoValue,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> TupleOrUnit<()> for T

Source§

fn into(self)