mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-24 00:00:14 +02:00
Add BytesMut::zeroed (#517)
This commit is contained in:
@@ -8,6 +8,7 @@ use alloc::{
|
|||||||
borrow::{Borrow, BorrowMut},
|
borrow::{Borrow, BorrowMut},
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
string::String,
|
string::String,
|
||||||
|
vec,
|
||||||
vec::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.
|
/// Splits the bytes into two at the given index.
|
||||||
///
|
///
|
||||||
/// Afterwards `self` contains elements `[0, at)`, and the returned
|
/// Afterwards `self` contains elements `[0, at)`, and the returned
|
||||||
|
|||||||
Reference in New Issue
Block a user