pub struct TokenThreshold {
pub max_tokens: u64,
pub keep_messages: usize,
}Expand description
Drop oldest non-system messages when token_estimate exceeds max_tokens.
Uses the same tail-preserving algorithm as crate::MaxMessages, keeping
at most keep_messages after the optional leading system message.
Fields§
§max_tokens: u64Token estimate that triggers compaction (must be >= 1).
keep_messages: usizeMessage count retained after compaction (must be >= 1).
Implementations§
Source§impl TokenThreshold
impl TokenThreshold
Sourcepub fn new(
max_tokens: u64,
keep_messages: usize,
) -> Result<TokenThreshold, MachiError>
pub fn new( max_tokens: u64, keep_messages: usize, ) -> Result<TokenThreshold, MachiError>
Construct a token-threshold strategy.
§Errors
Returns error when max_tokens == 0 or keep_messages == 0.
Trait Implementations§
Source§impl Clone for TokenThreshold
impl Clone for TokenThreshold
Source§fn clone(&self) -> TokenThreshold
fn clone(&self) -> TokenThreshold
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 CompactionStrategy for TokenThreshold
impl CompactionStrategy for TokenThreshold
Source§fn should_compact(&self, messages: &[Message], token_estimate: u64) -> bool
fn should_compact(&self, messages: &[Message], token_estimate: u64) -> bool
Whether compaction should run given current size estimates.
Source§fn compact(
&self,
messages: Vec<Message>,
) -> Result<CompactionOutcome, MachiError>
fn compact( &self, messages: Vec<Message>, ) -> Result<CompactionOutcome, MachiError>
Produce a compacted message list. Read more
impl Copy for TokenThreshold
Auto Trait Implementations§
impl Freeze for TokenThreshold
impl RefUnwindSafe for TokenThreshold
impl Send for TokenThreshold
impl Sync for TokenThreshold
impl Unpin for TokenThreshold
impl UnsafeUnpin for TokenThreshold
impl UnwindSafe for TokenThreshold
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