[][src]Struct nest::Store

pub struct Store { /* fields omitted */ }

The entry point for a Nest data store.

Stores start with a root path and use a schema to map the topology of your data structures with the filesystem (files and directories).

Example

Given a filesystem setup like:

$ tree /home/dinosaur/example
/home/dinosaur/example
└── hello
    └── world.json

$ cat /home/dinosaur/example/hello/world.json
{
  "nest": "🐣"
}

We can create a simple Nest data store with:

use std::convert::TryInto;
use serde_json::json;
use nest::{Error, Store, Value};

let root = "/home/dinosaur/example";
let schema = json!({
    "hello": {
        "world": "json"
    }
}).try_into()?;
let store = Store::new(root, schema);

Now we can use this store to get and set values.

let value = store.get(&["hello", "world", "nest"])?;
assert_eq!(value, Value::String("🐣".into()));

let next_value = Value::String("🐥".into());
store.set(&["hello", "world", "nest"], &next_value)?;

If we mostly care about data starting with a given path within the Nest, we can create a sub-Store that contains our path as a new root.

let sub = store.sub(&["hello", "world"])?;

let value = store.get(&["nest"])?;
assert_eq!(value, Value::String("🐥".into()));

let next_value = Value::String("🐔".into());
store.set(&["nest"], &next_value)?;

Methods

impl Store[src]

pub fn new<A>(root: A, schema: Schema) -> Self where
    A: Into<PathBuf>, 
[src]

Create a Store from root path and schema mapping.

pub fn get<A>(&self, path: A) -> Result<Value, Error> where
    A: Into<Path>, 
[src]

Get the Value at the given path.

pub fn set<A>(&self, path: A, value: &Value) -> Result<(), Error> where
    A: Into<Path>, 
[src]

Set the Value at the given path.

pub fn sub<A>(&self, path: A) -> Result<Store, Error> where
    A: Into<Path>, 
[src]

Return a sub-Store at the given path.

Auto Trait Implementations

impl Send for Store

impl Sync for Store

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]