Skip to main content

Store

Trait Store 

Source
pub trait Store: Files {
    // Required methods
    fn logs(&self) -> Result<Vec<String>>;
    fn read_log(&self, name: &str) -> Result<Vec<u8>>;
    fn append_log(
        &self,
        name: &str,
        len: u64,
        bytes: &[u8],
    ) -> Result<(), LogWriteError>;
    fn replace_log(
        &self,
        name: &str,
        len: u64,
        bytes: &[u8],
    ) -> Result<(), LogWriteError>;
    fn destroy(&self) -> Result<()>;
}
Expand description

Where a session is kept: its Files, with the content-addressed blobs its messages name under blobs/, and a log per agent plus the session’s own, appended to and read whole. Log names are one part of a name (check_name without /).

Required Methods§

Source

fn logs(&self) -> Result<Vec<String>>

The names of the logs, in no particular order.

Source

fn read_log(&self, name: &str) -> Result<Vec<u8>>

The whole log name; io::ErrorKind::NotFound when there is none.

Source

fn append_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Appends bytes to the log name if it is len bytes long now (0 when there is none, which it then starts); else LogWriteError::Changed, writing nothing. The check and the append are one step for every writer of the store, other processes included, so of two writers that read the log at the same length one appends and the other is refused. A log that shrank and grew back to exactly len bytes since it was read is not told apart; rig shrinks a log only by setting a torn last line aside, or by rewrite and Self::destroy, which are for a stopped session.

Source

fn replace_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Replaces the log name with bytes, under the condition Self::append_log has, atomically and durably: a reader, and a crash or power loss, leave the old log or the new, never a part of either or an empty file; an append after it goes after the new bytes. Starts the log when there is none.

Source

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

Removes everything the store holds: logs and files. Idempotent: calling it again after a crash midway finishes the job.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<S: Store + ?Sized> Store for Arc<S>

Source§

fn logs(&self) -> Result<Vec<String>>

Source§

fn read_log(&self, name: &str) -> Result<Vec<u8>>

Source§

fn append_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Source§

fn replace_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Source§

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

Source§

impl<S: Store + ?Sized> Store for Box<S>

Source§

fn logs(&self) -> Result<Vec<String>>

Source§

fn read_log(&self, name: &str) -> Result<Vec<u8>>

Source§

fn append_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Source§

fn replace_log( &self, name: &str, len: u64, bytes: &[u8], ) -> Result<(), LogWriteError>

Source§

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

Implementors§