[−][src]Struct nest::Store
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]
A: Into<PathBuf>,
Create a Store
from root
path and schema
mapping.
pub fn get<A>(&self, path: A) -> Result<Value, Error> where
A: Into<Path>,
[src]
A: Into<Path>,
Get the Value
at the given path
.
pub fn set<A>(&self, path: A, value: &Value) -> Result<(), Error> where
A: Into<Path>,
[src]
A: Into<Path>,
Set the Value
at the given path
.
pub fn sub<A>(&self, path: A) -> Result<Store, Error> where
A: Into<Path>,
[src]
A: Into<Path>,
Return a sub-Store
at the given path
.
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,