pub trait StageProcessor<Input, Output: Default, Config = ()>where
Config: Sync,{
// Required methods
fn stage_name(&self) -> &'static str;
fn process_item(
&self,
input: Input,
config: Option<&Config>,
) -> Result<Output, OCRError>;
// Provided methods
fn is_empty_input<I>(&self, input: &[I]) -> bool { ... }
fn empty_result(&self, start_time: Instant) -> StageResult<Vec<Output>>
where Output: Default { ... }
fn should_use_parallel(
&self,
item_count: usize,
config: Option<&Config>,
) -> bool { ... }
fn process_collection<I, F>(
&self,
items: Vec<I>,
config: Option<&Config>,
processor: F,
) -> Result<StageResult<Vec<Output>>, OCRError>
where I: Send,
Output: Send,
F: Fn(I, Option<&Config>) -> Result<Output, OCRError> + Send + Sync { ... }
}Expand description
Trait for stage processors that follow the common lifecycle pattern.
This trait provides a unified interface for stage processors that need to:
- Start timing operations
- Handle empty input collections
- Process items (potentially in parallel)
- Accumulate metrics
- Wrap results
§Design Note
This trait was designed to capture the common patterns found across
orientation, cropping, and recognition stage processors. However, in practice,
the concrete helper implementations ([crate::pipeline::stages::processor_helper])
proved more flexible and easier to use than this trait-based approach.
The trait remains for potential future use cases where a more formal interface is needed, but the helper utilities are recommended for most stage processor implementations.
Required Methods§
Sourcefn stage_name(&self) -> &'static str
fn stage_name(&self) -> &'static str
The name of the stage for metrics and logging
Provided Methods§
Sourcefn is_empty_input<I>(&self, input: &[I]) -> bool
fn is_empty_input<I>(&self, input: &[I]) -> bool
Check if the input collection is empty and should be handled specially
Sourcefn empty_result(&self, start_time: Instant) -> StageResult<Vec<Output>>where
Output: Default,
fn empty_result(&self, start_time: Instant) -> StageResult<Vec<Output>>where
Output: Default,
Create a result for empty input
Sourcefn should_use_parallel(
&self,
item_count: usize,
config: Option<&Config>,
) -> bool
fn should_use_parallel( &self, item_count: usize, config: Option<&Config>, ) -> bool
Determine if parallel processing should be used
Sourcefn process_collection<I, F>(
&self,
items: Vec<I>,
config: Option<&Config>,
processor: F,
) -> Result<StageResult<Vec<Output>>, OCRError>
fn process_collection<I, F>( &self, items: Vec<I>, config: Option<&Config>, processor: F, ) -> Result<StageResult<Vec<Output>>, OCRError>
Process a collection of items following the common lifecycle pattern
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.