pub struct ContextUsageSnapshot {
pub used_tokens: usize,
pub max_tokens: Option<usize>,
pub remaining_tokens: Option<usize>,
pub used_percent: Option<u8>,
pub source: TokenUsageSource,
pub prompt_tokens: usize,
pub cached_input_tokens: usize,
pub cache_creation_input_tokens: usize,
pub completion_tokens: usize,
pub reasoning_output_tokens: usize,
pub breakdown: Option<PromptTokenBreakdown>,
}Expand description
The model-visible context for the latest request. This is separate from cumulative session usage, which is an API/accounting total.
Fields§
§used_tokens: usize§max_tokens: Option<usize>§remaining_tokens: Option<usize>§used_percent: Option<u8>§source: TokenUsageSource§prompt_tokens: usize§cached_input_tokens: usize§cache_creation_input_tokens: usize§completion_tokens: usize§reasoning_output_tokens: usize§breakdown: Option<PromptTokenBreakdown>Implementations§
Source§impl ContextUsageSnapshot
impl ContextUsageSnapshot
pub fn from_usage(usage: &TokenUsage, max_tokens: Option<usize>) -> Self
pub fn from_estimate( breakdown: PromptTokenBreakdown, max_tokens: Option<usize>, ) -> Self
pub fn is_estimate(&self) -> bool
Sourcepub fn with_additional_tokens(self, extra: usize) -> Self
pub fn with_additional_tokens(self, extra: usize) -> Self
Return a copy with extra tokens folded into the running total. Used by
/context to add built-in tool-schema tokens that the reducer’s
MCP-only request estimate can’t see. Recomputes remaining_tokens and
used_percent; the breakdown is left untouched (the caller surfaces the
built-in figure on its own line so the MCP line stays accurate).
Trait Implementations§
Source§impl Clone for ContextUsageSnapshot
impl Clone for ContextUsageSnapshot
Source§fn clone(&self) -> ContextUsageSnapshot
fn clone(&self) -> ContextUsageSnapshot
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContextUsageSnapshot
impl Debug for ContextUsageSnapshot
Source§impl<'de> Deserialize<'de> for ContextUsageSnapshot
impl<'de> Deserialize<'de> for ContextUsageSnapshot
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
impl Eq for ContextUsageSnapshot
Source§impl PartialEq for ContextUsageSnapshot
impl PartialEq for ContextUsageSnapshot
Source§impl Serialize for ContextUsageSnapshot
impl Serialize for ContextUsageSnapshot
impl StructuralPartialEq for ContextUsageSnapshot
Auto Trait Implementations§
impl Freeze for ContextUsageSnapshot
impl RefUnwindSafe for ContextUsageSnapshot
impl Send for ContextUsageSnapshot
impl Sync for ContextUsageSnapshot
impl Unpin for ContextUsageSnapshot
impl UnsafeUnpin for ContextUsageSnapshot
impl UnwindSafe for ContextUsageSnapshot
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
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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>
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 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>
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