pub struct AlignedBuf { /* private fields */ }Expand description
An aligned byte buffer suitable for O_DIRECT I/O.
The buffer’s starting address is guaranteed to be aligned to alignment,
and its capacity is rounded up to a multiple of alignment.
Implementations§
Source§impl AlignedBuf
impl AlignedBuf
Sourcepub fn new(min_capacity: usize, alignment: usize) -> Result<Self>
pub fn new(min_capacity: usize, alignment: usize) -> Result<Self>
Allocate a new aligned buffer.
min_capacity is rounded up to the next multiple of alignment.
alignment must be a power of two.
Sourcepub fn with_default_alignment(min_capacity: usize) -> Result<Self>
pub fn with_default_alignment(min_capacity: usize) -> Result<Self>
Allocate with the default 4 KiB alignment.
Sourcepub fn write(&mut self, data: &[u8]) -> usize
pub fn write(&mut self, data: &[u8]) -> usize
Write bytes into the buffer. Returns the number of bytes written.
If the buffer doesn’t have enough remaining capacity, writes as much as possible and returns the count.
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Get the written portion of the buffer as a byte slice.
The returned slice starts at an aligned address.
Sourcepub fn as_aligned_slice(&self) -> &[u8] ⓘ
pub fn as_aligned_slice(&self) -> &[u8] ⓘ
Get the written portion padded up to the next alignment boundary.
O_DIRECT requires the I/O size to be a multiple of the block size.
The padding bytes are zeroed (from alloc_zeroed).
Sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Mutable raw pointer to the buffer start.