Minify implementation of Store::retrieve()
This commit is contained in:
parent
540348380e
commit
6c53f172dc
1 changed files with 10 additions and 16 deletions
|
@ -142,22 +142,16 @@ impl Store {
|
||||||
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
|
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
|
||||||
/// dropped, the new Entry is written to disk
|
/// dropped, the new Entry is written to disk
|
||||||
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
||||||
// get hold of the hashmap
|
self.entries
|
||||||
let hsmap = self.entries.write();
|
.write()
|
||||||
if hsmap.is_err() {
|
.map_err(|_| StoreError::new(StoreErrorKind::LockPoisoned, None))
|
||||||
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
.and_then(|mut es| {
|
||||||
}
|
let mut se = es.entry(id.clone()).or_insert_with(|| StoreEntry::new(id.clone()));
|
||||||
|
se.status = StoreEntryStatus::Borrowed;
|
||||||
// either get the existing entry ot create it
|
se.get_entry()
|
||||||
let mut entries = hsmap.unwrap();
|
})
|
||||||
let mut store_entry = entries.entry(id.clone()).or_insert_with(|| StoreEntry::new(id.clone()));
|
.map(|e| FileLockEntry::new(self, e, id))
|
||||||
|
}
|
||||||
// update the store entry status
|
|
||||||
store_entry.status = StoreEntryStatus::Borrowed;
|
|
||||||
|
|
||||||
// make a file lock entry from the store entry
|
|
||||||
store_entry.get_entry().map(|entry| FileLockEntry::new(self, entry, id))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Iterate over all StoreIds for one module name
|
/// Iterate over all StoreIds for one module name
|
||||||
pub fn retrieve_for_module(&self, mod_name: &str) -> StoreIdIterator {
|
pub fn retrieve_for_module(&self, mod_name: &str) -> StoreIdIterator {
|
||||||
|
|
Loading…
Reference in a new issue