File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use alloc::{
8
8
borrow:: { Borrow , BorrowMut } ,
9
9
boxed:: Box ,
10
10
string:: String ,
11
+ vec,
11
12
vec:: Vec ,
12
13
} ;
13
14
@@ -258,6 +259,22 @@ impl BytesMut {
258
259
}
259
260
}
260
261
262
+ /// Creates a new `BytesMut`, which is initialized with zero.
263
+ ///
264
+ /// # Examples
265
+ ///
266
+ /// ```
267
+ /// use bytes::BytesMut;
268
+ ///
269
+ /// let zeros = BytesMut::zeroed(42);
270
+ ///
271
+ /// assert_eq!(zeros.len(), 42);
272
+ /// zeros.into_iter().for_each(|x| assert_eq!(x, 0));
273
+ /// ```
274
+ pub fn zeroed ( len : usize ) -> BytesMut {
275
+ BytesMut :: from_vec ( vec ! [ 0 ; len] )
276
+ }
277
+
261
278
/// Splits the bytes into two at the given index.
262
279
///
263
280
/// Afterwards `self` contains elements `[0, at)`, and the returned
You can’t perform that action at this time.
0 commit comments