From 2c0cb1b6b8b4dd43677aa3518c38e635fb6e2edb Mon Sep 17 00:00:00 2001 From: Stepan Koltsov <stepan.koltsov@gmail.com> Date: Tue, 2 May 2017 21:23:20 +0300 Subject: [PATCH] BytesMut::new constructor (#114) --- src/bytes.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/bytes.rs b/src/bytes.rs index 4026b92..6964ce1 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -825,6 +825,30 @@ impl BytesMut { } } + /// Create a new `BytesMut` with default capacity. + /// + /// Resulting object has length 0 and unspecified capacity. + /// This function does not allocate. + /// + /// # Examples + /// + /// ``` + /// use bytes::{BytesMut, BufMut}; + /// + /// let mut bytes = BytesMut::new(); + /// + /// assert_eq!(0, bytes.len()); + /// + /// bytes.reserve(2); + /// bytes.put_slice(b"xy"); + /// + /// assert_eq!(&b"xy"[..], &bytes[..]); + /// ``` + #[inline] + pub fn new() -> BytesMut { + BytesMut::with_capacity(0) + } + /// Returns the number of bytes contained in this `BytesMut`. /// /// # Examples @@ -1302,7 +1326,7 @@ impl Eq for BytesMut { impl Default for BytesMut { #[inline] fn default() -> BytesMut { - BytesMut::with_capacity(0) + BytesMut::new() } } -- GitLab