#[non_exhaustive]pub struct Cost {
pub input: Option<f64>,
pub output: Option<f64>,
pub cache_read: Option<f64>,
pub cache_write: Option<f64>,
pub total: f64,
/* private fields */
}Expand description
What one or more turns cost, in USD. total is what was charged, or
when Self::is_complete is false, a lower bound of it.
A part is None when its source does not give it: a provider that
reports only a total leaves every part None, and one that reports
input and output leaves the cache parts None. A cost computed from
the catalog (Pricing::cost) leaves a
cache part None when the catalog lists no rate for it and the usage
has such tokens; its total then sums the known parts only, and it is
not complete. A part is never filled with a placeholder 0.0. Summing
costs keeps a part only when every side has it, and is complete only
when every side is. A None part is left out when serialized, and an
absent one reads back as None.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.input: Option<f64>Uncached input tokens.
output: Option<f64>Output tokens, reasoning included.
cache_read: Option<f64>Input tokens read from a cache.
cache_write: Option<f64>Input tokens written to a cache.
total: f64The whole charge, or a lower bound of it when the cost is not complete.
Implementations§
Source§impl Cost
impl Cost
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Whether Self::total is the whole charge.
false when a part the usage has tokens for had no known price, so
total is a lower bound.
Sourcepub fn from_parts(
input: f64,
output: f64,
cache_read: f64,
cache_write: f64,
) -> Self
pub fn from_parts( input: f64, output: f64, cache_read: f64, cache_write: f64, ) -> Self
A cost split into its parts, each known; total is their sum.
Sourcepub fn from_total(total: f64) -> Self
pub fn from_total(total: f64) -> Self
A cost known only as its total; every part is None.
Sourcepub fn input(self, input: impl Into<Option<f64>>) -> Self
pub fn input(self, input: impl Into<Option<f64>>) -> Self
Set, or with None clear, Self::input.
total is left as it is.
Sourcepub fn output(self, output: impl Into<Option<f64>>) -> Self
pub fn output(self, output: impl Into<Option<f64>>) -> Self
Set, or with None clear, Self::output.
total is left as it is.
Sourcepub fn cache_read(self, cache_read: impl Into<Option<f64>>) -> Self
pub fn cache_read(self, cache_read: impl Into<Option<f64>>) -> Self
Set, or with None clear, Self::cache_read.
total is left as it is.
Sourcepub fn cache_write(self, cache_write: impl Into<Option<f64>>) -> Self
pub fn cache_write(self, cache_write: impl Into<Option<f64>>) -> Self
Set, or with None clear, Self::cache_write.
total is left as it is.
Trait Implementations§
Source§impl Add for Cost
total always sums. Each part sums only when both sides know it, and is
None otherwise, so a summed part never understates what it covers. The
sum is complete only when both sides are.
impl Add for Cost
total always sums. Each part sums only when both sides know it, and is
None otherwise, so a summed part never understates what it covers. The
sum is complete only when both sides are.
impl Copy for Cost
Source§impl<'de> Deserialize<'de> for Cost
impl<'de> Deserialize<'de> for Cost
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>,
impl StructuralPartialEq for Cost
Auto Trait Implementations§
impl Freeze for Cost
impl RefUnwindSafe for Cost
impl Send for Cost
impl Sync for Cost
impl Unpin for Cost
impl UnsafeUnpin for Cost
impl UnwindSafe for Cost
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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