docs: Add rustdoc for filter_plugin, binary_detection, and lib.rs
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -4,20 +4,43 @@ use crate::common::PIPESIZE;
|
||||
use crate::services::filter_service::register_filter_plugin;
|
||||
|
||||
/// A filter that reads the first N bytes from the input stream.
|
||||
/// A filter that reads the first N bytes from the input stream.
|
||||
///
|
||||
/// Limits the output to the initial bytes specified in the configuration.
|
||||
/// Useful for previewing file contents without reading everything.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `remaining` - Number of bytes left to read before stopping.
|
||||
pub struct HeadBytesFilter {
|
||||
remaining: usize,
|
||||
}
|
||||
|
||||
/// A filter that reads the first N bytes from the input stream.
|
||||
///
|
||||
/// Limits the output to the initial bytes specified in the configuration.
|
||||
/// Useful for previewing file contents without reading everything.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `remaining` - Number of bytes left to read before stopping.
|
||||
impl HeadBytesFilter {
|
||||
/// Creates a new `HeadBytesFilter` that will read up to the specified number of bytes.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `count` - The maximum number of bytes to read from the input
|
||||
/// * `count` - The maximum number of bytes to read from the input.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Self` - A new instance of `HeadBytesFilter`
|
||||
/// A new instance configured to read at most `count` bytes.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let filter = HeadBytesFilter::new(1024);
|
||||
/// assert_eq!(filter.remaining, 1024);
|
||||
/// ```
|
||||
pub fn new(count: usize) -> Self {
|
||||
Self {
|
||||
remaining: count,
|
||||
@@ -25,19 +48,31 @@ impl HeadBytesFilter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Filters input by reading only the first N bytes and writing them to the output.
|
||||
///
|
||||
/// Reads from the input in chunks until the byte limit is reached or EOF, then writes
|
||||
/// the collected bytes to the output. Stops early if the limit is zero.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `reader` - Boxed mutable reference to the input data stream.
|
||||
/// * `writer` - Boxed mutable reference to the output stream.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - Success if filtering completes, or I/O error.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * `io::Error` from reading or writing operations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// // Assuming a filter chain with head_bytes(5)
|
||||
/// // Input "Hello World" becomes "Hello"
|
||||
/// ```
|
||||
impl FilterPlugin for HeadBytesFilter {
|
||||
/// Filters the input by reading only the first N bytes and writing them to the output.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `reader` - A boxed mutable reference to the input reader providing the data stream
|
||||
/// * `writer` - A boxed mutable reference to the output writer where filtered data is sent
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` -
|
||||
/// * `Ok(())` on success
|
||||
/// * `Err(io::Error)` if reading or writing fails
|
||||
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||
if self.remaining == 0 {
|
||||
return Ok(());
|
||||
@@ -58,9 +93,11 @@ impl FilterPlugin for HeadBytesFilter {
|
||||
|
||||
/// Clones this filter into a new boxed instance.
|
||||
///
|
||||
/// Creates an independent copy with the same configuration.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Box<dyn FilterPlugin>` - A new boxed clone of this filter
|
||||
/// A new `Box<dyn FilterPlugin>` clone.
|
||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||
Box::new(Self {
|
||||
remaining: self.remaining,
|
||||
@@ -69,9 +106,11 @@ impl FilterPlugin for HeadBytesFilter {
|
||||
|
||||
/// Returns the configuration options for this filter.
|
||||
///
|
||||
/// Defines the "count" parameter as required with no default.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Vec<FilterOption>` - A vector describing the filter's configurable parameters
|
||||
/// Vector of `FilterOption` describing parameters.
|
||||
fn options(&self) -> Vec<FilterOption> {
|
||||
vec![
|
||||
FilterOption {
|
||||
@@ -84,20 +123,43 @@ impl FilterPlugin for HeadBytesFilter {
|
||||
}
|
||||
|
||||
/// A filter that reads the first N lines from the input stream.
|
||||
/// A filter that reads the first N lines from the input stream.
|
||||
///
|
||||
/// Limits output to the initial lines specified, writing each full line to output.
|
||||
/// Handles line endings properly using buffered reading.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `remaining` - Number of lines left to read before stopping.
|
||||
pub struct HeadLinesFilter {
|
||||
remaining: usize,
|
||||
}
|
||||
|
||||
/// A filter that reads the first N lines from the input stream.
|
||||
///
|
||||
/// Limits output to the initial lines specified, writing each full line to output.
|
||||
/// Handles line endings properly using buffered reading.
|
||||
///
|
||||
/// # Fields
|
||||
///
|
||||
/// * `remaining` - Number of lines left to read before stopping.
|
||||
impl HeadLinesFilter {
|
||||
/// Creates a new `HeadLinesFilter` that will read up to the specified number of lines.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `count` - The maximum number of lines to read from the input
|
||||
/// * `count` - The maximum number of lines to read from the input.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Self` - A new instance of `HeadLinesFilter`
|
||||
/// A new instance configured to read at most `count` lines.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let filter = HeadLinesFilter::new(3);
|
||||
/// assert_eq!(filter.remaining, 3);
|
||||
/// ```
|
||||
pub fn new(count: usize) -> Self {
|
||||
Self {
|
||||
remaining: count,
|
||||
@@ -105,19 +167,30 @@ impl HeadLinesFilter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Filters input by reading only the first N lines and writing them to the output.
|
||||
///
|
||||
/// Uses buffered line reading to process input line-by-line until the limit or EOF.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `reader` - Boxed mutable reference to the input data stream.
|
||||
/// * `writer` - Boxed mutable reference to the output stream.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` - Success if filtering completes, or I/O error.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * `io::Error` from line reading or writing operations.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// // Assuming a filter chain with head_lines(2)
|
||||
/// // Input "Line1\nLine2\nLine3" becomes "Line1\nLine2\n"
|
||||
/// ```
|
||||
impl FilterPlugin for HeadLinesFilter {
|
||||
/// Filters the input by reading only the first N lines and writing them to the output.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `reader` - A boxed mutable reference to the input reader providing the data stream
|
||||
/// * `writer` - A boxed mutable reference to the output writer where filtered data is sent
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<()>` -
|
||||
/// * `Ok(())` on success
|
||||
/// * `Err(io::Error)` if reading or writing fails
|
||||
fn filter(&mut self, mut reader: Box<&mut dyn Read>, mut writer: Box<&mut dyn Write>) -> Result<()> {
|
||||
if self.remaining == 0 {
|
||||
return Ok(());
|
||||
@@ -137,9 +210,11 @@ impl FilterPlugin for HeadLinesFilter {
|
||||
|
||||
/// Clones this filter into a new boxed instance.
|
||||
///
|
||||
/// Creates an independent copy with the same configuration.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Box<dyn FilterPlugin>` - A new boxed clone of this filter
|
||||
/// A new `Box<dyn FilterPlugin>` clone.
|
||||
fn clone_box(&self) -> Box<dyn FilterPlugin> {
|
||||
Box::new(Self {
|
||||
remaining: self.remaining,
|
||||
@@ -148,9 +223,11 @@ impl FilterPlugin for HeadLinesFilter {
|
||||
|
||||
/// Returns the configuration options for this filter.
|
||||
///
|
||||
/// Defines the "count" parameter as required with no default.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Vec<FilterOption>` - A vector describing the filter's configurable parameters
|
||||
/// Vector of `FilterOption` describing parameters.
|
||||
fn options(&self) -> Vec<FilterOption> {
|
||||
vec![
|
||||
FilterOption {
|
||||
|
||||
Reference in New Issue
Block a user