Struct mvdb::Mvdb [] [src]

pub struct Mvdb<T> { /* fields omitted */ }

Minimum Viable Psuedo Database

Methods

impl<T> Mvdb<T> where
    T: Serialize + DeserializeOwned
[src]

[src]

Create a new Mvdb given data to contain and path to store. File will be created and written to immediately

Examples

let data = DemoData::new();
let file = Path::new("demo.json");

let my_data = Mvdb::new(data, &file)
    .expect("Could not write to file");

[src]

Create a new Mvdb given data to contain and path to store. File will be created and written to immediately. Information will be stored in a "pretty-print" JSON format, at the cost of additonal storage space and write time

Examples

let data = DemoData::new();
let file = Path::new("demo_pretty.json");

let my_data = Mvdb::new_pretty(data, &file)
    .expect("Could not write to file");

[src]

Create a new Mvdb given just the path. If the file does not exist, or the contained data does not match the schema of T, this will return an Error

Examples

let file = Path::new("demo.json");
let my_data: Mvdb<DemoData> = Mvdb::from_file(&file);
    .expect("File does not exist, or schema mismatch");

[src]

Create a new Mvdb given just the path. If the file does not exist, or the contained data does not match the schema of T, this will return an Error. Subsequent writes will be stored in a "pretty-print" JSON format, at the cost of additional storage space and write time. The file does not need to be "pretty-printed" before using this function

Examples

let file = Path::new("demo_pretty.json");
let my_data: Mvdb<DemoData> = Mvdb::from_file_pretty(&file);
    .expect("File does not exist, or schema mismatch");

[src]

Provide atomic read-only access to the database contents via a closure. Contents are accessed in-memory only, and will not re-read from the storage file, or cause any writes

Examples

let foo_from_disk = my_data.access(|db| db.foo.clone())
    .expect("Failed to access file");

[src]

Provide atomic writable access to the database contents via a closure. If the hash of the serialized contents after the access has changed, the database will be written to the file.

Examples

my_data.access_mut(|db: &mut DemoData| {
    db.baz = "New Value".into();
}).expect("Failed to access file");

impl<T> Mvdb<T> where
    T: Serialize + DeserializeOwned + Default
[src]

[src]

Attempt to load from a file. If the file does not exist, or if the schema does not match, a new file will be written with the default contents of T.

Examples

let file = Path::new("demo.json");
let my_data: Mvdb<DemoData> = Mvdb::from_file_or_default(&file);
    .expect("Could not write to file");

[src]

Attempt to load from a file. If the file does not exist, or if the schema does not match, a new file will be written with the default contents of T. Any writes made will use pretty-printed JSON

Examples

let file = Path::new("demo_pretty.json");
let my_data: Mvdb<DemoData> = Mvdb::from_file_or_default_pretty(&file);
    .expect("Could not write to file");

Trait Implementations

impl<T> Clone for Mvdb<T>
[src]

Implement Clone manually, otherwise Rust expects T to also impl Clone, which is not necessary

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<T> Send for Mvdb<T> where
    T: Send

impl<T> Sync for Mvdb<T> where
    T: Send