Skip to content

Commit

Permalink
feat: add with_capacity for ReaderStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys3 committed Aug 31, 2021
1 parent 9a97eb3 commit 1ff309b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tokio-util/src/io/reader_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ impl<R: AsyncRead> ReaderStream<R> {
buf: BytesMut::new(),
}
}

/// Convert an [`AsyncRead`] into a [`Stream`] with item type
/// `Result<Bytes, std::io::Error>`,
/// with a specific read buffer initial capacity.
///
/// [`AsyncRead`]: tokio::io::AsyncRead
/// [`Stream`]: futures_core::Stream
pub fn with_capacity(reader: R, capacity: usize) -> Self {
ReaderStream {
reader: Some(reader),
buf: BytesMut::with_capacity(capacity),
}
}
}

impl<R: AsyncRead> Stream for ReaderStream<R> {
Expand Down

0 comments on commit 1ff309b

Please sign in to comment.