use crate::contracts::pipeline::Pipeable;
use crate::http::{Request, Response};
use crate::pipeline;
use crate::pipeline::pipe::StepFn;
use std::future::Future;
#[derive(Clone)]
pub struct Pipeline {
inner: pipeline::Pipeline<Request, Response>,
}
impl Default for Pipeline {
fn default() -> Self {
Self::new()
}
}
impl Pipeline {
pub fn new() -> Self {
Self {
inner: pipeline::Pipeline::new(),
}
}
pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
pub(crate) fn compose(
&self,
destination: StepFn<Request, Response>,
) -> StepFn<Request, Response> {
self.inner.compose(destination)
}
pub fn send(mut self, request: Request) -> Self {
self.inner = self.inner.send(request);
self
}
pub fn through<I, P>(mut self, pipes: I) -> Self
where
I: IntoIterator<Item = P>,
P: Pipeable<Request, Response> + 'static,
{
self.inner = self.inner.through(pipes);
self
}
pub fn prepend<I, P>(mut self, pipes: I) -> Self
where
I: IntoIterator<Item = P>,
P: Pipeable<Request, Response> + 'static,
{
self.inner = self.inner.prepend(pipes);
self
}
pub fn append<I, P>(mut self, pipes: I) -> Self
where
I: IntoIterator<Item = P>,
P: Pipeable<Request, Response> + 'static,
{
self.inner = self.inner.append(pipes);
self
}
pub fn pipe<P>(mut self, pipe: P) -> Self
where
P: Pipeable<Request, Response> + 'static,
{
self.inner = self.inner.pipe(pipe);
self
}
pub async fn then<F, Fut>(self, destination: F) -> Response
where
F: Fn(Request) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Response> + Send + 'static,
{
self.inner.then(destination).await
}
}