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
use crate::pipeline::{
    marker::{BuildMap, Map},
    PipelineT,
};

use super::Service;

impl<SF, Arg, SF1> Service<Arg> for PipelineT<SF, SF1, BuildMap>
where
    SF: Service<Arg>,
    SF1: Clone,
{
    type Response = PipelineT<SF::Response, SF1, Map>;
    type Error = SF::Error;

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

impl<S, Req, F, Res> Service<Req> for PipelineT<S, F, Map>
where
    S: Service<Req>,
    F: Fn(S::Response) -> Res,
{
    type Response = Res;
    type Error = S::Error;

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