mirror of
https://github.com/Drop-OSS/dropbreak.git
synced 2026-07-18 09:57:53 -04:00
Fix examples
This commit is contained in:
@@ -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::<HashMap<String, String>, 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
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user