pub struct TokenBudgetEnforcer { /* private fields */ }Expand description
Token budget enforcer
Implements greedy token allocation by priority with optional truncation support.
Implementations§
Source§impl TokenBudgetEnforcer
impl TokenBudgetEnforcer
Sourcepub fn new(config: TokenBudgetConfig) -> Self
pub fn new(config: TokenBudgetConfig) -> Self
Create a new budget enforcer
Sourcepub fn with_budget(budget: usize) -> Self
pub fn with_budget(budget: usize) -> Self
Create with simple budget (for backwards compatibility)
Sourcepub fn with_estimator(budget: usize, estimator: TokenEstimator) -> Self
pub fn with_estimator(budget: usize, estimator: TokenEstimator) -> Self
Create with custom estimator
Sourcepub fn with_strategy(self, strategy: AllocationStrategy) -> Self
pub fn with_strategy(self, strategy: AllocationStrategy) -> Self
Set allocation strategy
Sourcepub fn reserve(&mut self, tokens: usize)
pub fn reserve(&mut self, tokens: usize)
Reserve tokens for overhead (headers, separators, etc.)
Sourcepub fn total_budget(&self) -> usize
pub fn total_budget(&self) -> usize
Get total budget
Sourcepub fn try_allocate(&self, tokens: usize) -> bool
pub fn try_allocate(&self, tokens: usize) -> bool
Try to allocate tokens (returns true if successful)
Sourcepub fn allocate_sections(&self, sections: &[BudgetSection]) -> BudgetAllocation
pub fn allocate_sections(&self, sections: &[BudgetSection]) -> BudgetAllocation
Allocate sections by priority (dispatches to strategy-specific method)
Sourcepub fn estimator(&self) -> &TokenEstimator
pub fn estimator(&self) -> &TokenEstimator
Get the estimator
Auto Trait Implementations§
impl !Freeze for TokenBudgetEnforcer
impl RefUnwindSafe for TokenBudgetEnforcer
impl Send for TokenBudgetEnforcer
impl Sync for TokenBudgetEnforcer
impl Unpin for TokenBudgetEnforcer
impl UnsafeUnpin for TokenBudgetEnforcer
impl UnwindSafe for TokenBudgetEnforcer
Blanket Implementations§
impl<T> Allocation for T
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> 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