Skip to main content

LedgerStore

Trait LedgerStore 

Source
pub trait LedgerStore {
    // Required methods
    fn ensure(&self, prefix: &str) -> Result<(), ReplicaError>;
    fn write(
        &self,
        prefix: &str,
        work: &mut dyn FnMut(&mut dyn LedgerTx) -> Result<(), ReplicaError>,
    ) -> Result<(), ReplicaError>;

    // Provided method
    fn read_record(
        &self,
        prefix: &str,
        collection: &str,
    ) -> Result<Option<CollectionRecord>, ReplicaError> { ... }
}
Expand description

A database the ledger can live in.

prefix names the tables (friends_ → friends_replica_collections); it is [A-Za-z0-9_]{0,48}, checked before any call.

Required Methods§

Source

fn ensure(&self, prefix: &str) -> Result<(), ReplicaError>

Creates the ledger’s tables if they do not exist. Idempotent.

Source

fn write( &self, prefix: &str, work: &mut dyn FnMut(&mut dyn LedgerTx) -> Result<(), ReplicaError>, ) -> Result<(), ReplicaError>

Runs work in one write transaction: everything it wrote is committed when it returns Ok, and nothing is when it returns Err. Two writers on the same ledger never interleave. work is called exactly once.

Provided Methods§

Source

fn read_record( &self, prefix: &str, collection: &str, ) -> Result<Option<CollectionRecord>, ReplicaError>

The collection’s header as last committed, read without taking the write lock: head() and a pull answered “nothing new” need nothing else. The default reads it inside LedgerStore::write; a store with a cheaper read overrides it.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§