diff --git a/src/stream.rs b/src/stream.rs index f63ca79..12c4637 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -18,6 +18,8 @@ mod blocking { sync::{Arc, Mutex}, }; + use crate::codec::Split; + /// reader part of a stream pub struct ReadHalf { /// inner stream @@ -66,6 +68,32 @@ mod blocking { try_lock!(self.inner).flush() } } + + #[cfg(feature = "sync_tls_rustls")] + impl Split for rustls_connector::TlsStream { + type R = ReadHalf>; + + type W = WriteHalf>; + + fn split(self) -> (Self::R, Self::W) { + let inner = Arc::new(Mutex::new(self)); + let inner_c = inner.clone(); + (ReadHalf { inner }, WriteHalf { inner: inner_c }) + } + } + + #[cfg(feature = "sync_tls_native")] + impl Split for native_tls::TlsStream { + type R = ReadHalf>; + + type W = WriteHalf>; + + fn split(self) -> (Self::R, Self::W) { + let inner = Arc::new(Mutex::new(self)); + let inner_c = inner.clone(); + (ReadHalf { inner }, WriteHalf { inner: inner_c }) + } + } } macro_rules! def {