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.

§Panics

Traps if this token has already been transferred (for example, sent to another agent through an RPC call or returned from a method). Split the token first if you need to both keep and send a capability.

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, or if this token has already been transferred.

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, or if either token has already been transferred.

Trait Implementations§

Source§

impl FromWire for QuotaToken

Source§

fn read_wire(reader: &mut WireReader, index: i32) -> Result<Self, WireError>

Source§

fn read_result_payload( reader: &mut WireReader, index: Option<i32>, ) -> Result<Self, WireError>

Source§

impl IntoWire for QuotaToken

Source§

fn preflight(&self, resources: &mut WirePreflight) -> Result<(), WireError>

Source§

fn write_wire(&self, writer: &mut WireWriter) -> Result<i32, WireError>

Source§

const NEEDS_PREPARATION: bool = true

False only when prepare_wire is a no-op for every value of this type. Resource preflight still runs regardless of this flag. Custom and derived implementations prepare by default, including those with no stream schema.
Source§

async fn prepare_wire(&self) -> Result<(), WireError>

Wrap native stream endpoints without reading from them. This is called only after the complete value has passed resource preflight.
Source§

fn write_result_payload( &self, writer: &mut WireWriter, ) -> Result<Option<i32>, WireError>

Source§

impl WireSchema for QuotaToken

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Resource for T
where T: 'static,

Source§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
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.
Source§

impl<T> TupleOrUnit<()> for T

Source§

fn into(self)