Skip to content

Commit

Permalink
io: add StreamReader::into_inner_with_chunk (#4559)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-naber authored Mar 23, 2022
1 parent 121769c commit f84c4d5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tokio-util/src/io/stream_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,24 @@ where
}

/// Do we have a chunk and is it non-empty?
fn has_chunk(self: Pin<&mut Self>) -> bool {
if let Some(chunk) = self.project().chunk {
fn has_chunk(&self) -> bool {
if let Some(ref chunk) = self.chunk {
chunk.remaining() > 0
} else {
false
}
}

/// Consumes this `StreamReader`, returning a Tuple consisting
/// of the underlying stream and an Option of the interal buffer,
/// which is Some in case the buffer contains elements.
pub fn into_inner_with_chunk(self) -> (S, Option<B>) {
if self.has_chunk() {
(self.inner, self.chunk)
} else {
(self.inner, None)
}
}
}

impl<S, B> StreamReader<S, B> {
Expand Down Expand Up @@ -118,6 +129,10 @@ impl<S, B> StreamReader<S, B> {
/// Consumes this `BufWriter`, returning the underlying stream.
///
/// Note that any leftover data in the internal buffer is lost.
/// If you additionally want access to the internal buffer use
/// [`into_inner_with_chunk`].
///
/// [`into_inner_with_chunk`]: crate::io::StreamReader::into_inner_with_chunk
pub fn into_inner(self) -> S {
self.inner
}
Expand Down

0 comments on commit f84c4d5

Please sign in to comment.