docs: Add Rustdoc comments to CompressionService methods

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 12:45:32 -03:00
parent e4fc653397
commit c145974ce3
3 changed files with 347 additions and 0 deletions

View File

@@ -71,6 +71,9 @@ pub struct FilterOption {
pub trait FilterPlugin: Send {
/// Processes the input stream and writes the filtered output.
///
/// This method reads from the input reader and applies filtering logic,
/// writing the processed data to the output writer.
///
/// # Arguments
///
/// * `reader` - A boxed mutable reference to the input reader providing the data to filter.
@@ -79,18 +82,64 @@ pub trait FilterPlugin: Send {
/// # Returns
///
/// A `Result` indicating success (`Ok(())`) or failure with an `io::Error`.
///
/// # Examples
///
/// ```
/// impl FilterPlugin for MyFilter {
/// fn filter(&mut self, reader: Box<&mut dyn Read>, writer: Box<&mut dyn Write>) -> Result<()> {
/// // Read and filter data
/// let mut buf = [0; 1024];
/// while let Ok(n) = reader.as_mut().read(&mut buf) {
/// if n == 0 { break; }
/// // Apply filter logic to buf[0..n]
/// writer.as_mut().write_all(&buf[0..n])?;
/// }
/// Ok(())
/// }
/// // ... other methods
/// }
/// ```
fn filter(&mut self, reader: Box<&mut dyn Read>, writer: Box<&mut dyn Write>) -> Result<()>;
/// Clones this plugin into a new boxed instance.
///
/// This method is required for dynamic dispatch and cloning in filter chains.
///
/// # Returns
///
/// A new `Box<dyn FilterPlugin>` clone of the current plugin.
///
/// # Examples
///
/// ```
/// fn clone_box(&self) -> Box<dyn FilterPlugin> {
/// Box::new(self.clone())
/// }
/// ```
fn clone_box(&self) -> Box<dyn FilterPlugin>;
/// Returns the configuration options for this plugin.
///
/// Describes the configurable parameters, including names, defaults, and required flags.
///
/// # Returns
///
/// A vector of `FilterOption` structs describing the plugin's options.
///
/// # Examples
///
/// ```
/// fn options(&self) -> Vec<FilterOption> {
/// vec![
/// FilterOption {
/// name: "pattern".to_string(),
/// default: None,
/// required: true,
/// },
/// ]
/// }
/// ```
fn options(&self) -> Vec<FilterOption>;
}
@@ -127,6 +176,22 @@ pub struct FilterChain {
plugins: Vec<Box<dyn FilterPlugin>>,
}
/// A chain of filter plugins applied sequentially.
///
/// Chains multiple filters, applying them in order to the input stream.
///
/// # Fields
///
/// * `plugins` - Vector of boxed filter plugins.
///
/// # Examples
///
/// ```
/// let mut chain = FilterChain::new();
/// chain.add_plugin(Box::new(HeadLinesFilter::new(10)));
/// chain.filter(&mut reader, &mut writer)?;
/// ```
impl Clone for FilterChain {
/// Clones this filter chain.
///
@@ -159,6 +224,13 @@ impl FilterChain {
/// # Returns
///
/// A new `FilterChain` with no plugins.
///
/// # Examples
///
/// ```
/// let chain = FilterChain::new();
/// assert!(chain.plugins.is_empty());
/// ```
pub fn new() -> Self {
Self {
plugins: Vec::new(),
@@ -167,15 +239,27 @@ impl FilterChain {
/// Adds a plugin to the chain.
///
/// Plugins are applied in the order they are added.
///
/// # Arguments
///
/// * `plugin` - The boxed filter plugin to add to the chain.
///
/// # Examples
///
/// ```
/// let mut chain = FilterChain::new();
/// chain.add_plugin(Box::new(GrepFilter::new("error".to_string())));
/// ```
pub fn add_plugin(&mut self, plugin: Box<dyn FilterPlugin>) {
self.plugins.push(plugin);
}
/// Applies the filter chain to the input and writes to the output.
///
/// If no plugins are present, data is copied directly from reader to writer.
/// For multiple plugins, intermediate results are buffered.
///
/// # Arguments
///
/// * `reader` - A mutable reference to the input reader providing the data stream.
@@ -184,6 +268,14 @@ impl FilterChain {
/// # Returns
///
/// A `Result` indicating success (`Ok(())`) or failure with an `io::Error` if any filter in the chain fails.
///
/// # Examples
///
/// ```
/// let mut chain = FilterChain::new();
/// chain.add_plugin(Box::new(HeadBytesFilter::new(100)));
/// chain.filter(&mut input_reader, &mut output_writer)?;
/// ```
pub fn filter(&mut self, reader: &mut dyn Read, writer: &mut dyn Write) -> Result<()> {
if self.plugins.is_empty() {
// If no plugins, just copy the input to output