From 463c182bccf5ee69796c4651f786032f23b20019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 16 Jan 2016 20:30:16 +0100 Subject: [PATCH] Use StoreEntry instead of a tuple --- libimagstore/src/store.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 61bb0ff2..632f3ce9 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -58,6 +58,25 @@ impl IntoStoreId for (ISI, ISI) { } } +struct StoreEntry { + file: File, + entry: Option, +} + +impl StoreEntry { + fn is_borrowed(&self) -> bool { + self.entry.is_none() + } + + fn set_entry(&mut self, entry: Entry) -> Result<()> { + self.entry = Some(entry); + unimplemented!() + } + + fn get_entry(&mut self) -> Result { + unimplemented!() + } +} pub struct Store { location: PathBuf, @@ -69,7 +88,7 @@ pub struct Store { * * Could be optimized for a threadsafe HashMap */ - entries: Arc)>>>, + entries: Arc>>, } impl Store { @@ -103,7 +122,7 @@ impl Drop for Store { */ fn drop(&mut self) { self.entries.write().unwrap() - .iter().map(|f| (f.1).0.unlock()); + .iter().map(|f| f.1.file.unlock()); } } @@ -141,8 +160,7 @@ impl<'a> ::std::ops::DerefMut for FileLockEntry<'a> { impl<'a> Drop for FileLockEntry<'a> { fn drop(&mut self) { let mut map = self.store.entries.write().unwrap(); - let (_, ref mut en) = *map.get_mut(&self.key).unwrap(); - *en = Some(self.entry.clone()); + map.get_mut(&self.key).unwrap().set_entry(self.entry.clone()); } }