Implement Store::load()

This commit is contained in:
Matthias Beyer 2015-12-28 00:04:54 +01:00
parent f29bcc7430
commit 23e4152aaa

View file

@ -1,3 +1,4 @@
use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
@ -14,7 +15,7 @@ use storage::file::hash::FileHash;
use storage::parser::{FileHeaderParser, Parser, ParserError}; use storage::parser::{FileHeaderParser, Parser, ParserError};
use storage::file::header::data::FileHeaderData; use storage::file::header::data::FileHeaderData;
type Cache = HashMap<FileID, RefCell<File>>; type Cache = HashMap<FileID, Rc<RefCell<File>>>;
pub struct Store { pub struct Store {
cache : RefCell<Cache>, cache : RefCell<Cache>,
@ -30,7 +31,7 @@ impl Store {
fn put_in_cache(&self, f: File) -> FileID { fn put_in_cache(&self, f: File) -> FileID {
let res = f.id().clone(); 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 res
} }
@ -113,8 +114,9 @@ impl Store {
unimplemented!() unimplemented!()
} }
pub fn load(&self, id: FileID) -> File { pub fn load(&self, id: &FileID) -> Option<Rc<RefCell<File>>> {
unimplemented!() debug!("Loading '{:?}'", id);
self.cache.borrow().get(id).cloned()
} }
fn get_new_file_id(&self) -> FileID { fn get_new_file_id(&self) -> FileID {