From f29bcc7430e5591ccc784f68c98c68b1b08a5aad Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 27 Dec 2015 23:51:44 +0100 Subject: [PATCH] Store: Put file into cache, return FileID --- src/storage/mod.rs | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index c278e6f6..290ede64 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -28,8 +28,14 @@ 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)); + res + } + pub fn new_file(&self, module: &Module) - -> &RefCell + -> FileID { let f = File { owning_module_name: module.name(), @@ -37,15 +43,17 @@ impl Store { data: String::from(""), id: self.get_new_file_id(), }; - debug!("Create new File object: {:?}", f); - f + + debug!("Create new File object: {:?}", &f); + self.put_in_cache(f) } pub fn new_file_from_parser_result(&self, module: &Module, id: FileID, header: FileHeaderData, - data: String) -> File + data: String) + -> FileID { let f = File { owning_module_name: module.name(), @@ -54,10 +62,14 @@ impl Store { id: id, }; debug!("Create new File object from parser result: {:?}", f); - f + self.put_in_cache(f) } - pub fn new_file_with_header(&self, module: &Module, h: FileHeaderData) -> File { + pub fn new_file_with_header(&self, + module: &Module, + h: FileHeaderData) + -> FileID + { let f = File { owning_module_name: module.name(), header: h, @@ -65,10 +77,12 @@ impl Store { id: self.get_new_file_id(), }; debug!("Create new File object with header: {:?}", f); - f + self.put_in_cache(f) } - pub fn new_file_with_data(&self, module: &Module, d: String) -> File { + pub fn new_file_with_data(&self, module: &Module, d: String) + -> FileID + { let f = File { owning_module_name: module.name(), header: FileHeaderData::Null, @@ -76,10 +90,15 @@ impl Store { id: self.get_new_file_id(), }; debug!("Create new File object with data: {:?}", f); - f + self.put_in_cache(f) } - pub fn new_file_with_content(&self, module: &Module, h: FileHeaderData, d: String) -> File { + pub fn new_file_with_content(&self, + module: &Module, + h: FileHeaderData, + d: String) + -> FileID + { let f = File { owning_module_name: module.name(), header: h, @@ -87,7 +106,7 @@ impl Store { id: self.get_new_file_id(), }; debug!("Create new File object with content: {:?}", f); - f + self.put_in_cache(f) } pub fn persist(&self, file: &File) -> bool {