Documentation cleanup #5

Manually merged
armin merged 10 commits from develop into master 2020-03-05 05:03:52 +00:00
2 changed files with 15 additions and 17 deletions
Showing only changes of commit 7833fcd354 - Show all commits

View file

@ -13,9 +13,11 @@ use std::{
path::Path, path::Path,
io::BufReader, io::BufReader,
fs::File, fs::File,
ops::Deref
}; };
#[allow(unused_imports)]
use std::ops::Deref; // we use this but rustc doesn't know
use quick_error::quick_error; use quick_error::quick_error;
use seckey::SecKey; use seckey::SecKey;

View file

@ -61,33 +61,29 @@ impl Coffer for CofferMap {
} }
} }
fn get(&self, key: &CofferKey) -> CofferResult<CofferValue> { fn get(&self, key: &CofferKey) -> Option<CofferValue> {
let lock = self.read(); let lock = self.read();
let res = lock.get(&key.shard) lock.get(&key.shard)
.and_then( |shard| { shard.get(&key.key) } ) .and_then( |shard| { shard.get(&key.key) } )
.ok_or(CofferError::Msg("Key not found"))?; .map(|o| o.clone())
Ok(res.clone())
} }
fn get_shard<T>(&self, shard: T) -> CofferResult<CofferShard> fn get_shard<T>(&self, shard: T) -> Option<CofferShard>
where T: AsRef<str> where T: AsRef<str>
{ {
let lock = self.read(); let lock = self.read();
debug!{"Coffer {:?}", *lock} debug!{"Coffer {:?}", *lock}
let coffer_shard = lock.get(shard.as_ref()) let map_to_vec = |map: &HashMap<String, CofferValue>| {
.ok_or(CofferError::Msg("Shard not found"))?; map.iter()
.map(|(k,v)| (k.clone(), v.clone()))
.collect::<Vec<(String, CofferValue)>>()
};
let mut res = CofferShard(Vec::new()); lock.get(shard.as_ref())
.and_then(|s| Some(CofferShard(map_to_vec(s))))
for (k,v) in coffer_shard {
res.0.push((k.clone(), v.clone()));
}
Ok(res)
} }
} }