Skip to main content

Store

Trait Store 

Source
pub trait Store: Send + Sync {
    // Required method
    fn save(&self, json: &str) -> Result<()>;

    // Provided method
    fn lock(&self) -> Result<Option<Locked>> { ... }
}
Expand description

Where a Purse saves its Holder after every change.

The JSON holds the secret key of every note, and notes are bearer: whoever reads it can spend them. Keep it somewhere private, encrypted at rest.

Required Methods§

Source

fn save(&self, json: &str) -> Result<()>

Replaces what was saved with json. Returns only once the data would survive a crash: the purse hands out keys and transfers only after this succeeds.

Provided Methods§

Source

fn lock(&self) -> Result<Option<Locked>>

Locks the store against other processes and reads what is saved in it, for a store more than one process writes. A purse calls it before every change: it makes the change to what was read here, saves, and only then drops the lock, so it never saves over a change another process made since it last looked.

The default returns None, for a store only one purse writes: the purse’s own holder is then always current.

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 save(&self, json: &str) -> Result<()>

Source§

fn lock(&self) -> Result<Option<Locked>>

Implementors§