pub struct TokenPool {
pub name: String,
pub capacity: u64,
pub used: u64,
pub reserved: u64,
}Expand description
A named token pool with a capacity limit.
Fields§
§name: StringPool name (e.g. “default”, “agent-123”, “batch-jobs”).
capacity: u64Maximum tokens allowed in this pool.
used: u64Tokens consumed so far.
reserved: u64Tokens currently reserved (pending completion).
Implementations§
Source§impl TokenPool
impl TokenPool
Sourcepub fn new(name: impl Into<String>, capacity: u64) -> Self
pub fn new(name: impl Into<String>, capacity: u64) -> Self
Create a new pool with the given capacity.
Sourcepub fn can_reserve(&self, tokens: u64) -> bool
pub fn can_reserve(&self, tokens: u64) -> bool
Whether the pool can accommodate tokens more.
Sourcepub fn commit(&mut self, reserved: u64, actual: u64)
pub fn commit(&mut self, reserved: u64, actual: u64)
Commit reserved tokens as used (after inference completes).
Sourcepub fn release(&mut self, tokens: u64)
pub fn release(&mut self, tokens: u64)
Release reserved tokens without using them (on failure/cancel).
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Utilisation ratio (0.0–1.0).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TokenPool
impl<'de> Deserialize<'de> for TokenPool
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for TokenPool
impl RefUnwindSafe for TokenPool
impl Send for TokenPool
impl Sync for TokenPool
impl Unpin for TokenPool
impl UnsafeUnpin for TokenPool
impl UnwindSafe for TokenPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more