mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-11 00:00:23 +02:00
Add BytesMut::zeroed (#517)
This commit is contained in:
@@ -8,6 +8,7 @@ use alloc::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
boxed::Box,
|
||||
string::String,
|
||||
vec,
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
@@ -258,6 +259,22 @@ impl BytesMut {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `BytesMut`, which is initialized with zero.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use bytes::BytesMut;
|
||||
///
|
||||
/// let zeros = BytesMut::zeroed(42);
|
||||
///
|
||||
/// assert_eq!(zeros.len(), 42);
|
||||
/// zeros.into_iter().for_each(|x| assert_eq!(x, 0));
|
||||
/// ```
|
||||
pub fn zeroed(len: usize) -> BytesMut {
|
||||
BytesMut::from_vec(vec![0; len])
|
||||
}
|
||||
|
||||
/// Splits the bytes into two at the given index.
|
||||
///
|
||||
/// Afterwards `self` contains elements `[0, at)`, and the returned
|
||||
|
||||
Reference in New Issue
Block a user