Skip to content

Commit 85ff7a3

Browse files
committed
Implement AsMut for session::Session and idle::Handle
This allows accessing inner stream and tweak its settings, for example disabling the read timeout during IDLE.
1 parent 8755b66 commit 85ff7a3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/client.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ impl<T: Read + Write + Unpin + fmt::Debug> Unpin for Session<T> {}
5757
impl<T: Read + Write + Unpin + fmt::Debug> Unpin for Client<T> {}
5858
impl<T: Read + Write + Unpin + fmt::Debug> Unpin for Connection<T> {}
5959

60+
// Make it possible to access the inner connection and modify its settings, such as read/write
61+
// timeouts.
62+
impl<T: Read + Write + Unpin + fmt::Debug> AsMut<T> for Session<T> {
63+
fn as_mut(&mut self) -> &mut T {
64+
self.conn.stream.as_mut()
65+
}
66+
}
67+
6068
/// An (unauthenticated) handle to talk to an IMAP server. This is what you get when first
6169
/// connecting. A succesfull call to [`Client::login`] or [`Client::authenticate`] will return a
6270
/// [`Session`] instance that provides the usual IMAP methods.

src/extensions/idle.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ pub enum IdleResponse {
9797
NewData(ResponseData),
9898
}
9999

100+
// Make it possible to access the inner connection and modify its settings, such as read/write
101+
// timeouts.
102+
impl<T: Read + Write + Unpin + fmt::Debug> AsMut<T> for Handle<T> {
103+
fn as_mut(&mut self) -> &mut T {
104+
self.session.conn.stream.as_mut()
105+
}
106+
}
107+
100108
impl<T: Read + Write + Unpin + fmt::Debug + Send> Handle<T> {
101109
unsafe_pinned!(session: Session<T>);
102110

0 commit comments

Comments
 (0)