diff --git a/examples/full.rs b/examples/full.rs index 288594e..9deb164 100644 --- a/examples/full.rs +++ b/examples/full.rs @@ -15,6 +15,9 @@ struct Person { } fn main() { + use std::collections::HashMap; + + use rustbreak::Container; let db = Database::from_path("test.yaml").unwrap(); println!("Writing to Database"); @@ -27,6 +30,8 @@ fn main() { name: String::from("Fred Johnson"), country: Country::UnitedKingdom }); + let map : &HashMap<_, _> = db.borrow(); + println!("Values: \n{:#?}", map.values()); }).unwrap(); println!("Syncing Database"); diff --git a/src/lib.rs b/src/lib.rs index e68cda7..cdd50e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,16 @@ pub trait Container : Debug { /// Borrows the given value from the Container fn get>(&self, key: T) -> Option<&V>; + + /// Gets the underlying storage container mutably + fn borrow_mut(&mut self) -> &mut Self { + self + } + + /// Gets the underlying storage container + fn borrow(&self) -> &Self { + self + } } impl Container for HashMap { @@ -97,7 +107,7 @@ type StringMap = HashMap; /// - D: Is the Data, you must specify this (usually inferred by the compiler) /// - C: Is the backing Container, per default HashMap /// - S: The Serializer/Deserializer or short DeSer. Per default `deser::Ron` is used -/// - F: The file backend. Per default it is in memory, but can be easily used with a file +/// - F: The storage backend. Per default it is in memory, but can be easily used with a file #[derive(Debug)] pub struct Database, S = Ron, F = RWVec> where