proto_tower_http_2/server/
make_layer.rs

1use crate::server::layer::ProtoHttp2Layer;
2use crate::server::parser::Http2Frame;
3use crate::ProtoHttp2Config;
4use std::marker::PhantomData;
5use tokio::sync::mpsc::{Receiver, Sender};
6use tower::{Layer, Service};
7
8/// This is the initializer for the layer.
9/// Invocations to the service will take the sender and receiver of the connection and process
10/// the full lifetime.
11pub struct ProtoHttp2MakeLayer<SERVICE>
12where
13    SERVICE: Service<(Receiver<Http2Frame>, Sender<Http2Frame>), Response = ()> + Send + Clone,
14{
15    phantom_data: PhantomData<SERVICE>,
16    config: ProtoHttp2Config,
17}
18
19impl<SERVICE> ProtoHttp2MakeLayer<SERVICE>
20where
21    SERVICE: Service<(Receiver<Http2Frame>, Sender<Http2Frame>), Response = ()> + Send + Clone,
22{
23    /// Create a new instance of the layer
24    pub fn new(config: ProtoHttp2Config) -> Self {
25        ProtoHttp2MakeLayer {
26            phantom_data: PhantomData,
27            config,
28        }
29    }
30}
31
32impl<SERVICE> Layer<SERVICE> for ProtoHttp2MakeLayer<SERVICE>
33where
34    SERVICE: Service<(Receiver<Http2Frame>, Sender<Http2Frame>), Response = ()> + Send + Clone,
35{
36    type Service = ProtoHttp2Layer<SERVICE>;
37
38    fn layer(&self, inner: SERVICE) -> Self::Service {
39        ProtoHttp2Layer::new(self.config.clone(), inner)
40    }
41}