Skip to content

Commit d6f7564

Browse files
committed
feat: add APIs to get references to underlying stream
This can be useful for example to get access to the peer address of the underlying TCP stream for logging purposes.
1 parent 81ec8ee commit d6f7564

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,16 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Session<T> {
13601360
impl<T: Read + Write + Unpin + fmt::Debug> Connection<T> {
13611361
unsafe_pinned!(stream: ImapStream<T>);
13621362

1363+
/// Gets a reference to the underlying stream.
1364+
pub fn get_ref(&self) -> &T {
1365+
self.stream.get_ref()
1366+
}
1367+
1368+
/// Gets a mutable reference to the underlying stream.
1369+
pub fn get_mut(&mut self) -> &mut T {
1370+
self.stream.get_mut()
1371+
}
1372+
13631373
/// Convert this connection into the raw underlying stream.
13641374
pub fn into_inner(self) -> T {
13651375
let Self { stream, .. } = self;

src/imap_stream.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
5454
Ok(())
5555
}
5656

57+
/// Gets a reference to the underlying stream.
58+
pub fn get_ref(&self) -> &R {
59+
&self.inner
60+
}
61+
62+
/// Gets a mutable reference to the underlying stream.
63+
pub fn get_mut(&mut self) -> &mut R {
64+
&mut self.inner
65+
}
66+
67+
/// Returns underlying stream.
5768
pub fn into_inner(self) -> R {
5869
self.inner
5970
}

0 commit comments

Comments
 (0)