micro_tower/api/layer.rs
1use std::marker::PhantomData;
2
3use super::Service;
4
5/// Creates a layer which wraps a given service inside an api translation layer (see [`Service`]).
6/// The api layer will translate requests of type `R` with codec `C`.
7pub struct Layer<R, C = super::codec::Json> {
8 _p: PhantomData<(R, C)>,
9}
10
11impl<R, C> Default for Layer<R, C> {
12 fn default() -> Self {
13 Self { _p: PhantomData }
14 }
15}
16
17impl<R, C, S> tower::Layer<S> for Layer<R, C> {
18 type Service = Service<R, C, S>;
19
20 fn layer(&self, inner: S) -> Self::Service {
21 Service::from_service(inner)
22 }
23}