Skip to main content

BatchOperation

Trait BatchOperation 

Source
pub trait BatchOperation: Send + Sync {
    type Output: Send;

    // Required methods
    fn process_file(&self, path: &Path) -> Result<Self::Output, CliError>;
    fn name(&self) -> &str;
}
Expand description

Trait for batch operations on HEDL files.

Implement this trait to define custom batch operations. The operation must be thread-safe (Send + Sync) to support parallel processing.

§Type Parameters

  • Output - The type returned on successful processing of a file

§Examples

use hedl_cli::batch::BatchOperation;
use hedl_cli::error::CliError;
use std::path::Path;

struct CountLinesOperation;

impl BatchOperation for CountLinesOperation {
    type Output = usize;

    fn process_file(&self, path: &Path) -> Result<Self::Output, CliError> {
        let content = std::fs::read_to_string(path)
            .map_err(|e| CliError::io_error(path, e))?;
        Ok(content.lines().count())
    }

    fn name(&self) -> &str {
        "count-lines"
    }
}

Required Associated Types§

Source

type Output: Send

The output type for successful processing

Required Methods§

Source

fn process_file(&self, path: &Path) -> Result<Self::Output, CliError>

Process a single file and return the result.

§Arguments
  • path - The path to the file to process
§Returns
  • Ok(Output) - On successful processing
  • Err(CliError) - On any error
§Errors

Should return appropriate CliError variants for different failure modes.

Source

fn name(&self) -> &str

Get a human-readable name for this operation.

Used for progress reporting and logging.

Implementors§