From 23e4152aaa4c08405a150b8b1b8ca1624a07dfc7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 28 Dec 2015 00:04:54 +0100 Subject: [PATCH] Implement Store::load() --- src/storage/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 290ede64..b35fa41f 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1,3 +1,4 @@ +use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; @@ -14,7 +15,7 @@ use storage::file::hash::FileHash; use storage::parser::{FileHeaderParser, Parser, ParserError}; use storage::file::header::data::FileHeaderData; -type Cache = HashMap>; +type Cache = HashMap>>; pub struct Store { cache : RefCell, @@ -30,7 +31,7 @@ impl Store { fn put_in_cache(&self, f: File) -> FileID { let res = f.id().clone(); - self.cache.borrow_mut().insert(f.id().clone(), RefCell::new(f)); + self.cache.borrow_mut().insert(f.id().clone(), Rc::new(RefCell::new(f))); res } @@ -113,8 +114,9 @@ impl Store { unimplemented!() } - pub fn load(&self, id: FileID) -> File { - unimplemented!() + pub fn load(&self, id: &FileID) -> Option>> { + debug!("Loading '{:?}'", id); + self.cache.borrow().get(id).cloned() } fn get_new_file_id(&self) -> FileID {