pub struct ExactBudgetEnforcer<C: TokenCounter> { /* private fields */ }Expand description
High-fidelity budget enforcer using exact token counting
Implementations§
Source§impl<C: TokenCounter> ExactBudgetEnforcer<C>
impl<C: TokenCounter> ExactBudgetEnforcer<C>
Sourcepub fn try_consume(&self, text: &str) -> Option<usize>
pub fn try_consume(&self, text: &str) -> Option<usize>
Try to consume budget for content Returns actual tokens consumed, or None if doesn’t fit
Sourcepub fn force_consume(&self, tokens: usize)
pub fn force_consume(&self, tokens: usize)
Force consume (for partial content)
Sourcepub fn truncate_to_fit(&self, text: &str) -> (String, usize)
pub fn truncate_to_fit(&self, text: &str) -> (String, usize)
Truncate text to fit remaining budget
Sourcepub fn summary(&self) -> BudgetSummary
pub fn summary(&self) -> BudgetSummary
Get budget usage summary
Auto Trait Implementations§
impl<C> !Freeze for ExactBudgetEnforcer<C>
impl<C> RefUnwindSafe for ExactBudgetEnforcer<C>where
C: RefUnwindSafe,
impl<C> Send for ExactBudgetEnforcer<C>
impl<C> Sync for ExactBudgetEnforcer<C>
impl<C> Unpin for ExactBudgetEnforcer<C>
impl<C> UnsafeUnpin for ExactBudgetEnforcer<C>
impl<C> UnwindSafe for ExactBudgetEnforcer<C>where
C: RefUnwindSafe,
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
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