Add borrow{_mut} to container

This commit is contained in:
Marcel Müller
2017-10-11 23:22:07 +02:00
parent 8810bc3b29
commit 294b7de5a2
2 changed files with 16 additions and 1 deletions
+5
View File
@@ -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");
+11 -1
View File
@@ -73,6 +73,16 @@ pub trait Container<V : Debug, K: Hash + Eq + Debug = String> : Debug {
/// Borrows the given value from the Container
fn get<T: AsRef<K>>(&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<V: Debug, K: Hash + Eq + Debug> Container<V, K> for HashMap<K, V> {
@@ -97,7 +107,7 @@ type StringMap<D> = HashMap<String, D>;
/// - D: Is the Data, you must specify this (usually inferred by the compiler)
/// - C: Is the backing Container, per default HashMap<String, D>
/// - 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<D, C = StringMap<D>, S = Ron, F = RWVec>
where