Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }
Expand description

A 4 KB-aligned, heap-allocated byte buffer suitable for O_DIRECT I/O.

Buffer owns a single contiguous allocation that is aligned to a FOUR_KB_BLOCK (4 096 bytes) — the minimum alignment required by O_DIRECT on all common block devices.

Cursor management is not handled here. Instead, FlushBuffer uses atomic fetch-and-add on its packed state word to hand out non-overlapping byte ranges to concurrent writers. This is what makes the unsafe impl Sync sound: no two threads are ever granted the same region.

§Safety

Sync is manually implemented because UnsafeCell opts out of it by default. The invariant that upholds this is: all mutable access to the inner pointer is mediated by FlushBuffer, which guarantees exclusive ranges per writer.

Implementations§

Source§

impl Buffer

Source

pub fn new_aligned(size: usize) -> Self

Allocate a zeroed, FOUR_KB_BLOCK-aligned buffer of size bytes.

§Panics

Panics if size is not a multiple of FOUR_KB_BLOCK, if the layout is otherwise invalid, or if the allocator returns a null pointer.

Trait Implementations§

Source§

impl Debug for Buffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Buffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Buffer

Source§

impl Sync for Buffer

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