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
39
40
41
42
43
use std::sync::Arc;

use bytes::Bytes;
use hyper::{Request, Response};
use tower::{Layer, Service};

use satex_core::config::ServeConfig;
use satex_core::http::Body;
use satex_core::{make, BoxError};
use satex_service::NamedRouteService;

use crate::NamedRouteServiceLayer;

make! {
    @compcat,
    MakeDefaultRouteServiceLayer,
    Layer,
    (Layer<NamedRouteService>),
    (&ServeConfig),
    NamedRouteServiceLayer
}

impl ArcMakeDefaultRouteServiceLayer {
    pub fn new<M, L, ResBody, E>(make: M) -> Self
    where
        M: MakeDefaultRouteServiceLayer<Layer = L> + Send + Sync + 'static,
        L: Layer<NamedRouteService> + Send + Sync + 'static,
        L::Service: Service<Request<Body>, Response = Response<ResBody>, Error = E>
            + Clone
            + Send
            + 'static,
        <<L as Layer<NamedRouteService>>::Service as Service<Request<Body>>>::Future:
            Send + 'static,
        ResBody: hyper::body::Body<Data = Bytes> + Send + 'static,
        ResBody::Error: Into<BoxError> + Send + 'static,
        E: Into<BoxError> + Send + 'static,
    {
        let name = make.name();
        Self(Arc::new(MakeFn::new(make, |inner| {
            NamedRouteServiceLayer::new(name, inner)
        })))
    }
}