Skip to main content

trillium_server_common/
acceptor.rs

1use crate::Transport;
2use std::{convert::Infallible, fmt::Debug, future::Future};
3
4/// This trait provides the common interface for server-side tls
5/// acceptors, abstracting over various implementations
6///
7/// The only implementation provided by this crate is `()`, which is
8/// a noop acceptor, and passes through the `Input` type.
9pub trait Acceptor<Input>: Clone + Send + Sync + 'static
10where
11    Input: Transport,
12{
13    /// The stream type. For example, `TlsStream<Input>`
14    type Output: Transport;
15
16    /// An error type that [`Acceptor::accept`] may return
17    type Error: Debug + Send + Sync;
18
19    /// Transform an Input (`AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static`) into
20    /// Self::Output
21    fn accept(
22        &self,
23        input: Input,
24    ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;
25
26    /// should conns be treated as secure?
27    fn is_secure(&self) -> bool {
28        true
29    }
30}
31
32impl<Input> Acceptor<Input> for ()
33where
34    Input: Transport,
35{
36    type Error = Infallible;
37    type Output = Input;
38
39    async fn accept(&self, input: Input) -> Result<Self::Output, Self::Error> {
40        Ok(input)
41    }
42
43    fn is_secure(&self) -> bool {
44        false
45    }
46}