use crate::{PipelineError, PipelineResult, PipelineStep};
pub struct Next<'a, TPassable, TError = PipelineError> {
pipes: &'a [PipelineStep<TPassable, TError>],
destination: &'a dyn Fn(TPassable) -> PipelineResult<TPassable, TError>,
}
impl<'a, TPassable, TError> Next<'a, TPassable, TError> {
pub(crate) fn new(
pipes: &'a [PipelineStep<TPassable, TError>],
destination: &'a dyn Fn(TPassable) -> PipelineResult<TPassable, TError>,
) -> Self {
Self { pipes, destination }
}
pub fn handle(self, passable: TPassable) -> PipelineResult<TPassable, TError> {
if let Some((pipe, rest)) = self.pipes.split_first() {
let next = Next::new(rest, self.destination);
pipe.handle(passable, next)
} else {
(self.destination)(passable)
}
}
}