summaryrefslogtreecommitdiffstats
path: root/tokio/src/io/util
diff options
context:
space:
mode:
authorVitor Enes <vitorenesduarte@gmail.com>2020-01-21 00:27:34 +0000
committerLucio Franco <luciofranco14@gmail.com>2020-01-20 19:27:34 -0500
commit3176d0a48a796c9d5437a76995bc11ca85390df4 (patch)
treea876215bb675d587430a43c484f44556d2e09c7a /tokio/src/io/util
parentbb6c3839ef0491310f40e4570b465bcc6b09ae95 (diff)
io: add `BufStream::with_capacity` (#2125)
Diffstat (limited to 'tokio/src/io/util')
-rw-r--r--tokio/src/io/util/buf_stream.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/tokio/src/io/util/buf_stream.rs b/tokio/src/io/util/buf_stream.rs
index 4fc6e725..12b213d0 100644
--- a/tokio/src/io/util/buf_stream.rs
+++ b/tokio/src/io/util/buf_stream.rs
@@ -33,6 +33,23 @@ impl<RW: AsyncRead + AsyncWrite> BufStream<RW> {
}
}
+ /// 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<RW> {
+ 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.