From 3176d0a48a796c9d5437a76995bc11ca85390df4 Mon Sep 17 00:00:00 2001 From: Vitor Enes Date: Tue, 21 Jan 2020 00:27:34 +0000 Subject: [PATCH] io: add `BufStream::with_capacity` (#2125) --- tokio/src/io/util/buf_stream.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tokio/src/io/util/buf_stream.rs b/tokio/src/io/util/buf_stream.rs index 4fc6e725d..12b213d09 100644 --- a/tokio/src/io/util/buf_stream.rs +++ b/tokio/src/io/util/buf_stream.rs @@ -33,6 +33,23 @@ impl BufStream { } } + /// Creates a `BufStream` with the specified [`BufReader`] capacity and [`BufWriter`] + /// capacity. + /// + /// See the documentation for those types and [`BufStream`] for details. + pub fn with_capacity( + reader_capacity: usize, + writer_capacity: usize, + stream: RW, + ) -> BufStream { + BufStream { + inner: BufReader::with_capacity( + reader_capacity, + BufWriter::with_capacity(writer_capacity, stream), + ), + } + } + /// Gets a reference to the underlying I/O object. /// /// It is inadvisable to directly read from the underlying I/O object.