pub struct TokenAccumulator { /* private fields */ }Expand description
Accumulates token fragments and tracks timing statistics.
Implementations§
Source§impl TokenAccumulator
impl TokenAccumulator
Sourcepub fn push_token(&mut self, token: &str)
pub fn push_token(&mut self, token: &str)
Append a token fragment.
Sourcepub fn time_to_first_token(&self) -> Option<Duration>
pub fn time_to_first_token(&self) -> Option<Duration>
Duration from the very first token to the very first token (i.e. always Some(0) after
the first push, but semantically “time to first token” measured at call site).
Returns None if no tokens have been pushed yet.
Sourcepub fn tokens_per_second(&self) -> f64
pub fn tokens_per_second(&self) -> f64
Tokens per second calculated over the full accumulation window.
Returns 0.0 if fewer than two tokens were pushed or no time has elapsed.
Sourcepub fn finish(&self) -> AccumulatorResult
pub fn finish(&self) -> AccumulatorResult
Snapshot the current accumulation state as an AccumulatorResult.
Sourcepub fn token_count(&self) -> usize
pub fn token_count(&self) -> usize
Number of tokens pushed so far.
Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
Total characters accumulated.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TokenAccumulator
impl RefUnwindSafe for TokenAccumulator
impl Send for TokenAccumulator
impl Sync for TokenAccumulator
impl Unpin for TokenAccumulator
impl UnsafeUnpin for TokenAccumulator
impl UnwindSafe for TokenAccumulator
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request