Skip to content

Commit 4527367

Browse files
committed
Allow getting a reference to the shared inner stream
1 parent e855f9e commit 4527367

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/stream.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ pub enum MaybeTlsStream<S> {
2424
Rustls(tokio_rustls::client::TlsStream<S>),
2525
}
2626

27+
impl<S> MaybeTlsStream<S> {
28+
/// Returns a shared reference to the inner stream.
29+
pub fn get_ref(&self) -> &S {
30+
match self {
31+
MaybeTlsStream::Plain(s) => s,
32+
#[cfg(feature = "native-tls")]
33+
MaybeTlsStream::NativeTls(s) => s.get_ref().get_ref().get_ref(),
34+
#[cfg(feature = "__rustls-tls")]
35+
MaybeTlsStream::Rustls(s) => s.get_ref().0,
36+
}
37+
}
38+
}
39+
2740
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRead for MaybeTlsStream<S> {
2841
fn poll_read(
2942
self: Pin<&mut Self>,

0 commit comments

Comments
 (0)