docs: Add Rustdoc to meta_plugin, filter_plugin, common, lib, and filter_service
Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -110,19 +110,24 @@ impl FilterService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Processes data with an optional filter string in a single call.
|
||||
/// Convenience method to apply filters to in-memory data and return the result.
|
||||
///
|
||||
/// This is a convenience method that creates a filter chain, applies it to the data,
|
||||
/// and returns the filtered result as a byte vector. Useful for simple one-off filtering.
|
||||
/// Parses the filter string, applies the chain to the data via Cursor I/O,
|
||||
/// and collects output into a Vec<u8>. Ideal for non-streaming use cases.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `data` - Input byte slice to process.
|
||||
/// * `filter_str` - Optional filter string to apply.
|
||||
/// * `data` - Input bytes to filter.
|
||||
/// * `filter_str` - Optional filter string specification.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Vec<u8>, io::Error>` - Filtered data or error if filtering fails.
|
||||
/// * `Ok(Vec<u8>)` - Filtered output bytes.
|
||||
/// * `Err(io::Error)` - If chain creation or filtering fails.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Propagates parsing or I/O errors.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -145,64 +150,57 @@ impl FilterService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Global registry for filter plugins.
|
||||
/// Global thread-safe registry for filter plugins.
|
||||
///
|
||||
/// This static variable holds a thread-safe map of filter plugin names to their
|
||||
/// constructors. Plugins register themselves at initialization time using
|
||||
/// `register_filter_plugin`. The registry is lazily initialized on first access.
|
||||
///
|
||||
/// # Usage
|
||||
///
|
||||
/// Plugins use this registry for dynamic loading:
|
||||
///
|
||||
/// ```rust
|
||||
/// static FILTER_PLUGIN_REGISTRY: Lazy<Mutex<HashMap<String, fn() -> Box<dyn FilterPlugin>>>> =
|
||||
/// Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
/// ```
|
||||
static FILTER_PLUGIN_REGISTRY: Lazy<Mutex<HashMap<String, fn() -> Box<dyn crate::filter_plugin::FilterPlugin>>>> =
|
||||
Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
/// Register a filter plugin with the global registry.
|
||||
///
|
||||
/// Adds a filter plugin to the registry so it can be dynamically loaded by name.
|
||||
/// This function is typically called at module initialization time using `#[ctor::ctor]`.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - The name of the filter plugin (e.g., "head_lines").
|
||||
/// * `constructor` - A function that returns a new `Box<dyn FilterPlugin>` instance.
|
||||
/// Lazily initialized Mutex<HashMap> mapping plugin names (e.g., "head_bytes") to their constructors.
|
||||
/// Plugins self-register via ctors at module load time. Used by the parser to instantiate filters dynamically.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the registry lock cannot be acquired (unlikely in normal use).
|
||||
/// Lock acquisition failures (rare) cause panics in accessors.
|
||||
static FILTER_PLUGIN_REGISTRY: Lazy<Mutex<HashMap<String, fn() -> Box<dyn crate::filter_plugin::FilterPlugin>>>> =
|
||||
Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
/// Registers a filter plugin in the global registry.
|
||||
///
|
||||
/// Called by plugin modules at initialization to enable dynamic loading by name.
|
||||
/// Supports plugin discovery and instantiation during filter chain parsing.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `name` - Unique string identifier for the plugin (e.g., "head_lines").
|
||||
/// * `constructor` - Zero-arg function returning a new boxed `FilterPlugin` instance.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if Mutex lock fails (unlikely).
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// register_filter_plugin("my_filter", || Box::new(MyFilter::new()));
|
||||
/// register_filter_plugin("custom_filter", || Box::new(CustomFilter::default()));
|
||||
/// ```
|
||||
pub fn register_filter_plugin(name: &str, constructor: fn() -> Box<dyn crate::filter_plugin::FilterPlugin>) {
|
||||
FILTER_PLUGIN_REGISTRY.lock().unwrap().insert(name.to_string(), constructor);
|
||||
}
|
||||
|
||||
/// Get a map of available filter plugins.
|
||||
/// Retrieves a snapshot of all registered filter plugins.
|
||||
///
|
||||
/// Returns a copy of the current registry contents, mapping plugin names to their constructors.
|
||||
/// This is useful for status reporting or plugin discovery.
|
||||
/// Clones the registry for safe iteration. Useful for status reporting, validation, or UI display of available filters.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// `HashMap<String, fn() -> Box<dyn FilterPlugin>>` - A clone of the registry map.
|
||||
/// HashMap clone with plugin names as keys and constructors as values.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the registry lock cannot be acquired.
|
||||
/// Panics if Mutex lock fails.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// let available = get_available_filter_plugins();
|
||||
/// assert!(available.contains_key("head_lines"));
|
||||
/// let plugins = get_available_filter_plugins();
|
||||
/// assert!(plugins.contains_key("head_bytes"));
|
||||
/// ```
|
||||
pub fn get_available_filter_plugins() -> HashMap<String, fn() -> Box<dyn crate::filter_plugin::FilterPlugin>> {
|
||||
FILTER_PLUGIN_REGISTRY.lock().unwrap().clone()
|
||||
|
||||
Reference in New Issue
Block a user