io: add StreamReader::into_inner_with_chunk (#4559)

This commit is contained in:
b-naber
2022-03-23 20:41:09 +01:00
committed by GitHub
parent 121769c762
commit f84c4d596a
+17 -2
View File
@@ -84,13 +84,24 @@ where
} }
/// Do we have a chunk and is it non-empty? /// Do we have a chunk and is it non-empty?
fn has_chunk(self: Pin<&mut Self>) -> bool { fn has_chunk(&self) -> bool {
if let Some(chunk) = self.project().chunk { if let Some(ref chunk) = self.chunk {
chunk.remaining() > 0 chunk.remaining() > 0
} else { } else {
false 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> { impl<S, B> StreamReader<S, B> {
@@ -118,6 +129,10 @@ impl<S, B> StreamReader<S, B> {
/// Consumes this `BufWriter`, returning the underlying stream. /// Consumes this `BufWriter`, returning the underlying stream.
/// ///
/// Note that any leftover data in the internal buffer is lost. /// 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 { pub fn into_inner(self) -> S {
self.inner self.inner
} }