diff --git a/README.md b/README.md index 07476f0..440fc68 100644 --- a/README.md +++ b/README.md @@ -41,20 +41,22 @@ Usage is quite simple: - Don't forget to run `flush` periodically ```rust -use rustbreak::Database; +# use std::collections::HashMap; +use rustbreak::{MemoryDatabase, deser::Ron}; -fn main() { - let db = Database::memory(); +let db = MemoryDatabase::, Ron>::memory(HashMap::new(), Ron); - db.insert("Lapfox".into(), "lapfoxtrax.com") - db.insert("Rust".into(), "github.com/rust-lang/rust") +println!("Writing to Database"); +db.write(|db| { + db.insert("hello".into(), String::from("world")); + db.insert("foo".into(), String::from("bar")); +}); - // we need to be explicit about the kind of type we want as println! is - // generic - let rust : String = db.retrieve("Rust").unwrap(); - println!("You can find Rust at: {}", rust); - db.flush().unwrap(); -} +db.read(|db| { + // db.insert("foo".into(), String::from("bar")); + // The above line will not compile since we are only reading + println!("Hello: {:?}", db.get("hello")); +}); ``` ### Yaml diff --git a/examples/switching.rs b/examples/switching.rs index 762e63f..5f09894 100644 --- a/examples/switching.rs +++ b/examples/switching.rs @@ -1,7 +1,7 @@ extern crate rustbreak; #[macro_use] extern crate serde_derive; -use rustbreak::{FileDatabase, FileBackend}; +use rustbreak::{FileDatabase, backend::FileBackend}; use rustbreak::deser::{Ron, Yaml}; #[derive(Eq, PartialEq, Debug, Serialize, Deserialize, Clone)]