Skip to main content

FileBackend

Trait FileBackend 

Source
pub trait FileBackend: Sized {
    // Required methods
    fn len(&self) -> Result<u64>;
    fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>;
    fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>;
    fn set_len(&self, new_len: u64) -> Result<()>;
    fn sync_data(&self, mode: SyncMode) -> Result<()>;
    fn sync_all(&self) -> Result<()>;

    // Provided method
    fn is_empty(&self) -> Result<bool> { ... }
}
Expand description

File-backend abstraction the pager and WAL build on.

FileBackend is the common subset of FileHandle operations that fault-injection harnesses and the production type both expose (Rule 9). Production code never holds dyn FileBackend; both crate::pager::Pager and crate::wal::Wal are generic over F: FileBackend so the dispatch stays monomorphised.

New methods added to this trait MUST mirror an existing FileHandle method exactly. Adding a method that does not exist on the production type would let the harness perform syscalls production code cannot — a forbidden divergence (the harness must be a strict superset of legal behaviour, never a separate kingdom).

Required Methods§

Source

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

Length of the file in bytes. See FileHandle::len.

§Errors

Returns Error::Io on syscall failure.

Source

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

Positioned read. See FileHandle::read_exact_at.

§Errors

Returns Error::Io on syscall failure or harness-injected short read.

Source

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

Positioned write. See FileHandle::write_all_at.

§Errors

Returns Error::Io on syscall failure.

Source

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

Truncate or extend the file. See FileHandle::set_len.

§Errors

Returns Error::Io on syscall failure.

Source

fn sync_data(&self, mode: SyncMode) -> Result<()>

See FileHandle::sync_data.

§Errors

Returns Error::Io on syscall failure.

Source

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

See FileHandle::sync_all.

§Errors

Returns Error::Io on syscall failure.

Provided Methods§

Source

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

true iff the file has zero length.

§Errors

Returns Error::Io on syscall failure.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§