1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::pipeline::{
    marker::{AndThen, BuildAndThen},
    PipelineT,
};

use super::Service;

impl<SF, Arg, SF1> Service<Arg> for PipelineT<SF, SF1, BuildAndThen>
where
    SF: Service<Arg>,
    Arg: Clone,
    SF1: Service<Arg>,
    SF1::Error: From<SF::Error>,
{
    type Response = PipelineT<SF::Response, SF1::Response, AndThen>;
    type Error = SF1::Error;

    async fn call(&self, arg: Arg) -> Result<Self::Response, Self::Error> {
        let first = self.first.call(arg.clone()).await?;
        let second = self.second.call(arg).await?;
        Ok(PipelineT::new(first, second))
    }
}

impl<S, Req, S1> Service<Req> for PipelineT<S, S1, AndThen>
where
    S: Service<Req>,
    S1: Service<S::Response, Error = S::Error>,
{
    type Response = S1::Response;
    type Error = S::Error;

    #[inline]
    async fn call(&self, req: Req) -> Result<Self::Response, Self::Error> {
        let res = self.first.call(req).await?;
        self.second.call(res).await
    }
}