light_magic::atomic

Trait DataStore

source
pub trait DataStore: Default + Serialize {
    // Provided methods
    fn open<P>(db: P) -> AtomicDatabase<Self>
       where P: AsRef<Path>,
             Self: DeserializeOwned { ... }
    fn open_in_memory() -> AtomicDatabase<Self>
       where Self: DeserializeOwned { ... }
    fn load(file: impl Read) -> Result<Self>
       where Self: Sized + DeserializeOwned { ... }
    fn save(&self, file: impl Write) -> Result<()> { ... }
}
Expand description

This trait needs to be implemented for the Database struct. It requires a few implementations. The defined functions have default definitions.

Provided Methods§

source

fn open<P>(db: P) -> AtomicDatabase<Self>
where P: AsRef<Path>, Self: DeserializeOwned,

Opens a Database by the specified path. If the Database doesn’t exist, this will create a new one! Wrap a Arc<_> around it to use it in parallel contexts!

source

fn open_in_memory() -> AtomicDatabase<Self>
where Self: DeserializeOwned,

Creates a Database instance in memory. Wrap a Arc<_> around it to use it in parallel contexts!

source

fn load(file: impl Read) -> Result<Self>
where Self: Sized + DeserializeOwned,

Loads file data into the Database

source

fn save(&self, file: impl Write) -> Result<()>

Saves data of the Database to a file

Object Safety§

This trait is not object safe.

Implementors§