StageProcessor

Trait StageProcessor 

Source
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§

Source

fn stage_name(&self) -> &'static str

The name of the stage for metrics and logging

Source

fn process_item( &self, input: Input, config: Option<&Config>, ) -> Result<Output, OCRError>

Process a single item

Provided Methods§

Source

fn is_empty_input<I>(&self, input: &[I]) -> bool

Check if the input collection is empty and should be handled specially

Source

fn empty_result(&self, start_time: Instant) -> StageResult<Vec<Output>>
where Output: Default,

Create a result for empty input

Source

fn should_use_parallel( &self, item_count: usize, config: Option<&Config>, ) -> bool

Determine if parallel processing should be used

Source

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,

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.

Implementors§