pub struct UsageLedger { /* private fields */ }Implementations§
Source§impl UsageLedger
impl UsageLedger
pub fn new() -> Self
pub fn with_ttl(ttl: Duration) -> Self
Sourcepub fn record(
&mut self,
request_id: RequestId,
attempt_id: AttemptId,
prompt_tokens: u64,
completion_tokens: u64,
total_tokens: u64,
) -> InsertOutcome
pub fn record( &mut self, request_id: RequestId, attempt_id: AttemptId, prompt_tokens: u64, completion_tokens: u64, total_tokens: u64, ) -> InsertOutcome
Record a completed attempt’s usage. Returns InsertOutcome::is_new()
false when the same (request, attempt) was already recorded, which the
caller must treat as a no-op billing event.
pub fn is_empty(&self) -> bool
Sourcepub fn contains(&self, request_id: &RequestId, attempt_id: &AttemptId) -> bool
pub fn contains(&self, request_id: &RequestId, attempt_id: &AttemptId) -> bool
True when a usage record exists for this (request, attempt) pair.
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Total tokens recorded across all distinct attempts.
Sourcepub fn sweep_expired(&mut self)
pub fn sweep_expired(&mut self)
Drops records older than the TTL. Called lazily on every record and
available explicitly for maintenance. The clock read is floored to the
ledger’s monotonic timestamp so a backwards jump cannot expire freshly
recorded rows.
Trait Implementations§
Source§impl Debug for UsageLedger
impl Debug for UsageLedger
Auto Trait Implementations§
impl Freeze for UsageLedger
impl RefUnwindSafe for UsageLedger
impl Send for UsageLedger
impl Sync for UsageLedger
impl Unpin for UsageLedger
impl UnsafeUnpin for UsageLedger
impl UnwindSafe for UsageLedger
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