use crate::{AsyncPipelineDestination, AsyncPipelineFuture, AsyncPipelineStep, PipelineError};
pub struct AsyncNext<'a, TPassable, TError = PipelineError> {
pipes: &'a [AsyncPipelineStep<TPassable, TError>],
destination: &'a AsyncPipelineDestination<'a, TPassable, TError>,
}
impl<'a, TPassable, TError> AsyncNext<'a, TPassable, TError>
where
TPassable: Send + 'a,
TError: Send + 'a,
{
pub(crate) fn new(
pipes: &'a [AsyncPipelineStep<TPassable, TError>],
destination: &'a AsyncPipelineDestination<'a, TPassable, TError>,
) -> Self {
Self { pipes, destination }
}
pub fn handle(self, passable: TPassable) -> AsyncPipelineFuture<'a, TPassable, TError> {
Box::pin(async move {
if let Some((pipe, rest)) = self.pipes.split_first() {
let next = AsyncNext::new(rest, self.destination);
pipe.handle(passable, next).await
} else {
(self.destination)(passable).await
}
})
}
}