Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
    type Error: Debug;

    // Required methods
    fn read_snapshot(&mut self) -> Result<Option<Vec<u8>>, Self::Error>;
    fn write_snapshot(&mut self, bytes: &[u8]) -> Result<(), Self::Error>;
    fn read_journal(&mut self) -> Result<Vec<u8>, Self::Error>;
    fn append_journal(&mut self, entry: &[u8]) -> Result<(), Self::Error>;
    fn clear_journal(&mut self) -> Result<(), Self::Error>;
}
Expand description

Where snapshot and journal bytes live.

The engine calls append_journal synchronously at the end of every mutating operation — that call is the durability point. Fsync policy, atomicity of write_snapshot (tmp + rename) and locking are the implementation’s business, not the core’s.

Required Associated Types§

Source

type Error: Debug

Implementation-specific failure (I/O error, host callback error…).

Required Methods§

Source

fn read_snapshot(&mut self) -> Result<Option<Vec<u8>>, Self::Error>

The full snapshot image, or None when no database exists yet (first run).

Source

fn write_snapshot(&mut self, bytes: &[u8]) -> Result<(), Self::Error>

Atomically replaces the snapshot image.

Source

fn read_journal(&mut self) -> Result<Vec<u8>, Self::Error>

All journal bytes accumulated since the last snapshot (empty is normal).

Source

fn append_journal(&mut self, entry: &[u8]) -> Result<(), Self::Error>

Appends one framed journal entry (see crate::journal).

Source

fn clear_journal(&mut self) -> Result<(), Self::Error>

Discards the journal (called after a successful snapshot).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§