Skip to main content

TokenUsage

Struct TokenUsage 

Source
pub struct TokenUsage {
    pub prompt_tokens: u64,
    pub cached_prompt_tokens: u64,
    pub input_image_tokens: u64,
    pub input_audio_tokens: u64,
    pub content_tokens: u64,
    pub reasoning_tokens: u64,
    pub tool_call_tokens: u64,
    pub undeterminable_tokens: u64,
}

Fields§

§prompt_tokens: u64§cached_prompt_tokens: u64§input_image_tokens: u64§input_audio_tokens: u64§content_tokens: u64§reasoning_tokens: u64§tool_call_tokens: u64§undeterminable_tokens: u64

Implementations§

Source§

impl TokenUsage

Source

pub const fn new() -> TokenUsage

Source

pub const fn record_prompt_tokens(&mut self, count: u64)

Source

pub const fn record_cached_prompt_tokens( &mut self, count: u64, ) -> Result<(), TokenUsageError>

§Errors

Returns TokenUsageError::CachedExceedsPrompt when the running cached total would exceed Self::prompt_tokens.

Source

pub const fn record_input_image_tokens(&mut self, count: u64)

Source

pub const fn record_input_audio_tokens(&mut self, count: u64)

Source

pub const fn record_content_token(&mut self)

Source

pub const fn record_reasoning_token(&mut self)

Source

pub const fn record_tool_call_token(&mut self)

Source

pub const fn record_undeterminable_token(&mut self)

Source

pub const fn completion_tokens(&self) -> u64

Source

pub const fn total_tokens(&self) -> u64

Trait Implementations§

Source§

impl Add<&TokenUsage> for TokenUsage

Source§

type Output = TokenUsage

The resulting type after applying the + operator.
Source§

fn add(self, other: &TokenUsage) -> TokenUsage

Performs the + operation. Read more
Source§

impl Add for TokenUsage

Source§

type Output = TokenUsage

The resulting type after applying the + operator.
Source§

fn add(self, other: TokenUsage) -> TokenUsage

Performs the + operation. Read more
Source§

impl AddAssign<&TokenUsage> for TokenUsage

Source§

fn add_assign(&mut self, other: &TokenUsage)

Performs the += operation. Read more
Source§

impl AddAssign for TokenUsage

Source§

fn add_assign(&mut self, other: TokenUsage)

Performs the += operation. Read more
Source§

impl Clone for TokenUsage

Source§

fn clone(&self) -> TokenUsage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenUsage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for TokenUsage

Source§

fn default() -> TokenUsage

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TokenUsage

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<TokenUsage, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for TokenUsage

Source§

fn eq(&self, other: &TokenUsage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TokenUsage

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'usage> Sum<&'usage TokenUsage> for TokenUsage

Source§

fn sum<TIter>(iter: TIter) -> TokenUsage
where TIter: Iterator<Item = &'usage TokenUsage>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for TokenUsage

Source§

fn sum<TIter>(iter: TIter) -> TokenUsage
where TIter: Iterator<Item = TokenUsage>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Copy for TokenUsage

Source§

impl Eq for TokenUsage

Source§

impl StructuralPartialEq for TokenUsage

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,