use crate::result::Result;
use crate::SweepProcessor;
use nexrad_model::data::SweepField;
pub struct SweepPipeline {
steps: Vec<Box<dyn SweepProcessor>>,
}
impl SweepPipeline {
pub fn new() -> Self {
Self { steps: Vec::new() }
}
pub fn then(mut self, processor: impl SweepProcessor + 'static) -> Self {
self.steps.push(Box::new(processor));
self
}
pub fn execute(&self, input: &SweepField) -> Result<SweepField> {
if self.steps.is_empty() {
return Ok(input.clone());
}
let mut current = self.steps[0].process(input)?;
for step in &self.steps[1..] {
current = step.process(¤t)?;
}
Ok(current)
}
}
impl Default for SweepPipeline {
fn default() -> Self {
Self::new()
}
}
impl SweepProcessor for SweepPipeline {
fn name(&self) -> &str {
"Pipeline"
}
fn process(&self, input: &SweepField) -> Result<SweepField> {
self.execute(input)
}
}