async-email / async-native-tls

Native TLS for futures and async-std
Apache License 2.0
70 stars 21 forks source link

Proposal: A shared trait for tls acceptors that are implemented by both async-tls and async-native-tls #27

Open jbr opened 3 years ago

jbr commented 3 years ago

I have some code that implements this using wrapper types, but would really love for a trait like this to exist:

A proposed async-tls-acceptor crate that publishes this trait:

#[async_trait]
pub trait Acceptor<Input>: Clone + Send + Sync + 'static
where
    Input: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
{
    type Output: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static;
    type Error: std::fmt::Debug + Send + Sync;

    async fn accept(&self, input: Input) -> Result<Self::Output, Self::Error>;
}

The implementation for async-native-tls would be:

#[async_trait]
impl<Input> Acceptor<Input> for async_native_tls::TlsAcceptor
where
    Input: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,
{
    type Output = async_native_tls::TlsStream<Input>;
    type Error = async_native_tls::Error;
    async fn accept(&self, input: Input) -> Result<Self::Output, Self::Error> {
        async_native_tls::TlsAcceptor::accept(&self, input).await
    }
}

Would this be welcomed?

refs: https://github.com/async-rs/async-tls/issues/43

flub commented 3 years ago

at first sight this seems reasonable to me. Let's see what async-tls thinks about this as well.