pub struct TokenVelocity { /* private fields */ }Expand description
Sliding-window token counter.
Implementations§
Source§impl TokenVelocity
impl TokenVelocity
Sourcepub fn new(window_ms: u64) -> Self
pub fn new(window_ms: u64) -> Self
Create a tracker with the given window size in milliseconds.
Sourcepub fn record_at(&self, now_ms: u64, tokens: u64) -> u64
pub fn record_at(&self, now_ms: u64, tokens: u64) -> u64
Record tokens at time now_ms and return the windowed total.
Sourcepub fn current_at(&self, now_ms: u64) -> u64
pub fn current_at(&self, now_ms: u64) -> u64
Windowed total without recording.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TokenVelocity
impl !RefUnwindSafe for TokenVelocity
impl Send for TokenVelocity
impl Sync for TokenVelocity
impl Unpin for TokenVelocity
impl UnsafeUnpin for TokenVelocity
impl UnwindSafe for TokenVelocity
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<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> 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