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)?;