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
44
45
46
use crate::Transport;
use std::{convert::Infallible, fmt::Debug, future::Future};
/// This trait provides the common interface for server-side tls
/// acceptors, abstracting over various implementations
///
/// The only implementation provided by this crate is `()`, which is
/// a noop acceptor, and passes through the `Input` type.
pub trait Acceptor<Input>: Clone + Send + Sync + 'static
where
Input: Transport,
{
/// The stream type. For example, `TlsStream<Input>`
type Output: Transport;
/// An error type that [`Acceptor::accept`] may return
type Error: Debug + Send + Sync;
/// Transform an Input (`AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static`) into
/// Self::Output
fn accept(
&self,
input: Input,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;
/// should conns be treated as secure?
fn is_secure(&self) -> bool {
true
}
}
impl<Input> Acceptor<Input> for ()
where
Input: Transport,
{
type Error = Infallible;
type Output = Input;
async fn accept(&self, input: Input) -> Result<Self::Output, Self::Error> {
Ok(input)
}
fn is_secure(&self) -> bool {
false
}
}