Skip to main content

CompressionPolicy

Trait CompressionPolicy 

Source
pub trait CompressionPolicy: Send + Sync {
    // Required method
    fn should_compress<'life0, 'async_trait>(
        &'life0 self,
        tokens_before: usize,
        msg_count: usize,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Compression policy trait — controls whether compression should proceed.

Framework provides default implementations. Users can implement custom policies (e.g., user confirmation, rate limiting, etc.).

§Communication pattern

  • Framework → User: via CompressionEvent (event notification)
  • User → Framework: via should_compress() return value (bool)

Required Methods§

Source

fn should_compress<'life0, 'async_trait>( &'life0 self, tokens_before: usize, msg_count: usize, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called before compression starts.

§Arguments
  • tokens_before — estimated token count of current messages
  • msg_count — number of messages in the session
§Returns
  • true — proceed with compression
  • false — skip compression, keep current messages

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§