mirror of
https://github.com/Drop-OSS/dropbreak.git
synced 2026-07-18 09:57:53 -04:00
Add borrow{_mut} to container
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user