@@ -75,15 +75,16 @@ impl<R: Read + Write + Unpin> ImapStream<R> {
75
75
}
76
76
77
77
impl < R : Read + Write + Unpin > ImapStream < R > {
78
- fn maybe_decode ( & mut self ) -> io:: Result < Option < ResponseData > > {
79
- if self . buffer . used ( ) >= self . decode_needs {
80
- self . decode ( )
81
- } else {
82
- Ok ( None )
78
+ /// Attempts to decode a single response from the buffer.
79
+ ///
80
+ /// Returns `None` if the buffer does not contain enough data.
81
+ fn decode ( & mut self ) -> io:: Result < Option < ResponseData > > {
82
+ if self . buffer . used ( ) < self . decode_needs {
83
+ // We know that there is not enough data to decode anything
84
+ // from previous attempts.
85
+ return Ok ( None ) ;
83
86
}
84
- }
85
87
86
- fn decode ( & mut self ) -> io:: Result < Option < ResponseData > > {
87
88
let block: Block < ' static > = self . buffer . take_block ( ) ;
88
89
// Be aware, now self.buffer is invalid until block is returned or reset!
89
90
@@ -259,7 +260,7 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
259
260
260
261
fn poll_next ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
261
262
let this = & mut * self ;
262
- if let Some ( response) = this. maybe_decode ( ) ? {
263
+ if let Some ( response) = this. decode ( ) ? {
263
264
return Poll :: Ready ( Some ( Ok ( response) ) ) ;
264
265
}
265
266
loop {
@@ -287,7 +288,7 @@ impl<R: Read + Write + Unpin> Stream for ImapStream<R> {
287
288
return Poll :: Ready ( None ) ;
288
289
}
289
290
this. buffer . extend_used ( num_bytes_read) ;
290
- if let Some ( response) = this. maybe_decode ( ) ? {
291
+ if let Some ( response) = this. decode ( ) ? {
291
292
return Poll :: Ready ( Some ( Ok ( response) ) ) ;
292
293
}
293
294
}
0 commit comments