pub struct BatchProcessor { /* private fields */ }Expand description
High-performance batch processor for HEDL files.
Orchestrates parallel or serial processing based on configuration and workload. Provides progress tracking and comprehensive error collection.
§Thread Safety
BatchProcessor is thread-safe and can be shared across threads via Arc.
§Examples
use hedl_cli::batch::{BatchProcessor, BatchConfig, ValidationOperation};
use std::path::PathBuf;
let processor = BatchProcessor::new(BatchConfig {
parallel_threshold: 5,
verbose: true,
..Default::default()
});
let files: Vec<PathBuf> = vec![
"file1.hedl".into(),
"file2.hedl".into(),
];
let results = processor.process(
&files,
ValidationOperation { strict: false },
true,
)?;
if results.has_failures() {
eprintln!("Some files failed validation");
for failure in results.failures() {
eprintln!(" - {}: {:?}", failure.path.display(), failure.result);
}
}Implementations§
Source§impl BatchProcessor
impl BatchProcessor
Sourcepub fn new(config: BatchConfig) -> Self
pub fn new(config: BatchConfig) -> Self
Create a new batch processor with the given configuration.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Create a batch processor with default configuration.
Sourcepub fn process<O>(
&self,
files: &[PathBuf],
operation: O,
show_progress: bool,
) -> Result<BatchResults<O::Output>, CliError>where
O: BatchOperation,
pub fn process<O>(
&self,
files: &[PathBuf],
operation: O,
show_progress: bool,
) -> Result<BatchResults<O::Output>, CliError>where
O: BatchOperation,
Process multiple files with the given operation.
Automatically selects parallel or serial processing based on configuration and file count. Provides progress reporting and collects all results.
§Arguments
files- Slice of file paths to processoperation- The operation to perform on each fileshow_progress- Whether to show progress updates
§Returns
Ok(BatchResults)- Always succeeds and collects all individual resultsErr(CliError)- Only on catastrophic failures (e.g., thread pool creation)
§Performance
- Uses parallel processing if
files.len() >= config.parallel_threshold - Serial processing for small batches to avoid thread pool overhead
- Lock-free progress tracking using atomic counters
§Examples
use hedl_cli::batch::{BatchProcessor, BatchConfig, FormatOperation};
use std::path::PathBuf;
let processor = BatchProcessor::default_config();
let files = vec![PathBuf::from("a.hedl"), PathBuf::from("b.hedl")];
let results = processor.process(
&files,
FormatOperation {
check: false,
ditto: true,
with_counts: false,
},
true,
)?;
println!("Formatted {} files", results.success_count());Trait Implementations§
Source§impl Clone for BatchProcessor
impl Clone for BatchProcessor
Source§fn clone(&self) -> BatchProcessor
fn clone(&self) -> BatchProcessor
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BatchProcessor
impl RefUnwindSafe for BatchProcessor
impl Send for BatchProcessor
impl Sync for BatchProcessor
impl Unpin for BatchProcessor
impl UnwindSafe for BatchProcessor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more