StageAlgorithm

Trait StageAlgorithm 

Source
pub trait StageAlgorithm<Input, Output> {
    // Required method
    fn run(&self, input: Input) -> Result<Output, OCRError>;
}
Expand description

Trait for stage algorithms that can be run with automatic timing and metrics.

This trait provides a clean interface for implementing stage processing logic while delegating the common concerns (timing, metrics, error handling) to the generic stage harness.

§Example

struct TextRecognitionAlgorithm {
    predictor: TextRecPredictor,
}

impl StageAlgorithm<RgbImage, String> for TextRecognitionAlgorithm {
    fn run(&self, input: RgbImage) -> Result<String, OCRError> {
        // Implement the core recognition logic
        self.predictor.predict(vec![input], None)
            .map(|results| results.into_iter().next().unwrap_or_default())
    }
}

// Use with the generic harness
let algorithm = TextRecognitionAlgorithm { predictor };
let result = run_with_metrics("text_recognition", images, &algorithm, None)?;

Required Methods§

Source

fn run(&self, input: Input) -> Result<Output, OCRError>

Run the algorithm on a single input item.

This method should contain the core processing logic without worrying about timing, metrics, or error handling patterns.

Implementors§