Skip to main content

AlignedBuf

Struct AlignedBuf 

Source
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

Source

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.

Source

pub fn with_default_alignment(min_capacity: usize) -> Result<Self>

Allocate with the default 4 KiB alignment.

Source

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.

Source

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.

Source

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).

Source

pub fn clear(&mut self)

Reset the buffer for reuse without deallocating.

Source

pub fn len(&self) -> usize

Current number of bytes written.

Source

pub fn is_empty(&self) -> bool

Whether the buffer has no written data.

Source

pub fn capacity(&self) -> usize

Total capacity of the buffer.

Source

pub fn remaining(&self) -> usize

Remaining capacity.

Source

pub fn alignment(&self) -> usize

The alignment of this buffer.

Source

pub fn as_ptr(&self) -> *const u8

Raw pointer to the buffer start (for io_uring submission).

Source

pub fn as_mut_ptr(&mut self) -> *mut u8

Mutable raw pointer to the buffer start.

Trait Implementations§

Source§

impl Drop for AlignedBuf

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for AlignedBuf

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more