Struct DirectIoFile

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

Wrapper data structure for direct/unbuffered/uncached I/O.

Depending on OS, this will use direct I/O, unbuffered, uncaches passthrough file reads/writes, bypassing as much of OS machinery as possible.

NOTE: There are major alignment requirements described here: https://learn.microsoft.com/en-us/windows/win32/fileio/file-buffering#alignment-and-file-access-requirements https://man7.org/linux/man-pages/man2/open.2.html

Implementations§

Source§

impl DirectIoFile

Source

pub fn open<P>(options: OpenOptions, path: P) -> Result<Self>
where P: AsRef<Path>,

Open a file with basic open options at the specified path for direct/unbuffered I/O for reads and writes.

options allows configuring things like read/write/create/truncate, but custom options will be overridden internally.

This is especially important on Windows to prevent huge memory usage.

Source

pub fn len(&self) -> Result<u64>

Get file size

Source

pub fn is_empty(&self) -> Result<bool>

Returns Ok(true) if the file is empty

Source

pub fn allocate(&self, len: u64) -> Result<()>

Make sure the file has a specified number of bytes allocated on the disk.

Later writes within len will not fail due to lack of disk space.

Source

pub fn set_len(&self, len: u64) -> Result<()>

Truncates or extends the underlying file, updating the size of this file to become len.

Note if len is larger than the previous file size, it will result in a sparse file. If you’d like to pre-allocate space on disk, use Self::allocate(), which may be followed by this method to truncate the file if the new file size is smaller than the previous (Self::allocate() doesn’t truncate the file).

Source

pub fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>

Read the exact number of bytes needed to fill buf at offset.

NOTE: This uses locking and buffering internally, prefer Self::write_all_at_raw() if you can control data alignment.

Source

pub fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>

Write all bytes at buf at offset.

NOTE: This uses locking and buffering internally, prefer Self::write_all_at_raw() if you can control data alignment.

Source

pub fn read_exact_at_raw( &self, buf: &mut [AlignedPageSize], offset: u64, ) -> Result<()>

Low-level reading into aligned memory.

offset needs to be page-aligned as well or use Self::read_exact_at() if you’re willing to pay for the corresponding overhead.

Source

pub fn write_all_at_raw( &self, buf: &[AlignedPageSize], offset: u64, ) -> Result<()>

Low-level writing from aligned memory.

offset needs to be page-aligned as well or use Self::write_all_at() if you’re willing to pay for the corresponding overhead.

Source

pub fn file(&self) -> &File

Access internal File instance

Trait Implementations§

Source§

impl Debug for DirectIoFile

Source§

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

Formats the value using the given formatter. Read more

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.