Skip to main content

FileIo

Trait FileIo 

Source
pub trait FileIo: Send + Sync {
Show 13 methods // Required methods fn requires_alignment(&self) -> bool; fn read_at(&self, buf: &mut [u8], off: u64) -> Result<()>; fn write_at(&self, buf: &[u8], off: u64) -> Result<()>; fn sync_data(&self) -> Result<()>; fn sync_full(&self) -> Result<()>; fn sync_full_primitive(&self) -> &'static str; fn sync_dir(&self) -> Result<()>; fn len(&self) -> Result<u64>; fn set_len(&self, n: u64) -> Result<()>; // Provided methods fn manages_free_pages(&self) -> bool { ... } fn pop_free_page(&self) -> Result<Option<u32>> { ... } fn push_free_page(&self, _page: u32) -> Result<()> { ... } fn stats(&self) -> Option<&IoStats> { ... }
}

Required Methods§

Source

fn requires_alignment(&self) -> bool

True when this file demands page-aligned offsets, lengths and buffers. The WAL is byte-addressed and always opens Buffered, so it never does.

Source

fn read_at(&self, buf: &mut [u8], off: u64) -> Result<()>

Source

fn write_at(&self, buf: &[u8], off: u64) -> Result<()>

Source

fn sync_data(&self) -> Result<()>

A data barrier that does NOT force the drive’s own write cache: the write is durable against an OS crash, not necessarily against a loss of power to the drive. fdatasync on Linux; plain fsync on macOS.

Deliberately not std::fs::File::sync_data: libstd’s implementation calls fcntl(F_FULLFSYNC) on macOS (a safety choice in std, not a bug), which is exactly the strong, ~65x-costlier barrier sync_full exists to name separately. Going through it here would make Normal and Full issue the identical primitive on macOS while differing on Linux – the SyncMode label would say one thing and the hardware would hear another, and differently on different platforms.

Source

fn sync_full(&self) -> Result<()>

The strongest barrier this platform can issue: durable even against a loss of power to the drive. fcntl(F_FULLFSYNC) on macOS (roughly 65x the cost of sync_data on the same hardware); File::sync_all (ordinary fsync) elsewhere.

Source

fn sync_full_primitive(&self) -> &'static str

The exact primitive sync_full issues on this platform, so a measurement can state what it did rather than imply it.

Source

fn sync_dir(&self) -> Result<()>

Source

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

Source

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

Provided Methods§

Source

fn manages_free_pages(&self) -> bool

Experimental transactional allocator; ordinary files retain pool reuse.

Source

fn pop_free_page(&self) -> Result<Option<u32>>

Source

fn push_free_page(&self, _page: u32) -> Result<()>

Source

fn stats(&self) -> Option<&IoStats>

This file’s counters, if it keeps any. Defaulted so test doubles need no change.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§