pub struct TokenReservation { /* private fields */ }Expand description
Reservation handle returned by TokenBudget::try_reserve_tokens.
The handle carries the estimate for one model call so reconciliation is per-call even when multiple prompts are outstanding concurrently.
§Cancellation semantics
Dropping a TokenReservation without calling
TokenBudget::record_usage is treated as cancellation: the full
estimate is refunded to the budget via the closure supplied at
construction. Implementations of TokenBudget::record_usage must
call TokenReservation::disarm to suppress the refund-on-drop
before performing their own reconciliation.
Implementations§
Source§impl TokenReservation
impl TokenReservation
Sourcepub fn new(estimate: u64, refund: TokenRefund) -> Self
pub fn new(estimate: u64, refund: TokenRefund) -> Self
Construct a reservation. Intended for TokenBudget
implementations only.
Sourcepub fn disarm(&mut self) -> Option<TokenRefund>
pub fn disarm(&mut self) -> Option<TokenRefund>
Take ownership of the refund closure, suppressing the
refund-on-drop. Returns None if the reservation has already
been disarmed (which would indicate misuse).
TokenBudget::record_usage implementations must disarm the
reservation they receive before reconciling against actual
usage; otherwise the refund-on-drop would double-credit the
pool.