remove example; add with_capacity_aligned_zeroed

Signed-off-by: Yuchen Liang <yuchen@neon.tech>
This commit is contained in:
Yuchen Liang
2024-09-29 20:57:41 +00:00
parent 9e9d76d6f2
commit e01d145066

View File

@@ -40,16 +40,6 @@ impl IoBufferMut {
/// * `capacity`, when rounded up to the nearest multiple of `align`,
/// must not overflow isize (i.e., the rounded value must be
/// less than or equal to `isize::MAX`).
///
/// # Examples
///
/// ```
/// let mut buf = IoBufferMut::with_capacity_aligned(4096, 4096);
///
/// assert_eq!(buf.len(), 0);
/// assert_eq!(buf.capacity(), 4096);
/// assert_eq!(buf.align(), 4096);
/// ```
pub fn with_capacity_aligned(capacity: usize, align: usize) -> Self {
let layout = Layout::from_size_align(capacity, align).expect("Invalid layout");
@@ -70,6 +60,13 @@ impl IoBufferMut {
}
}
pub fn with_capacity_aligned_zeroed(capacity: usize, align: usize) -> Self {
use bytes::BufMut;
let mut buf = Self::with_capacity_aligned(capacity, align);
buf.put_bytes(0, capacity);
buf
}
/// Returns the total number of bytes the buffer can hold.
#[inline]
pub fn capacity(&self) -> usize {