From 470f1b1378915193ee389d7d722960d05baeb794 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 27 Dec 2015 23:46:08 +0100 Subject: [PATCH] Save only module name in File, not whole module --- src/storage/file/mod.rs | 28 ++++++++++++++-------------- src/storage/mod.rs | 37 ++++++++++++++++++++++--------------- src/ui/file.rs | 6 +++--- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/storage/file/mod.rs b/src/storage/file/mod.rs index 165c0276..c22b0e5a 100644 --- a/src/storage/file/mod.rs +++ b/src/storage/file/mod.rs @@ -23,14 +23,18 @@ use self::header::data::*; * Internal abstract view on a file. Does not exist on the FS and is just kept * internally until it is written to disk. */ -pub struct File<'a> { - pub owning_module : &'a Module<'a>, - pub header : FileHeaderData, - pub data : String, - pub id : FileID, +pub struct File { + pub owning_module_name : &'static str, + pub header : FileHeaderData, + pub data : String, + pub id : FileID, } -impl<'a> File<'a> { +impl File { + + pub fn owner_name(&self) -> &'static str { + self.owning_module_name + } pub fn header(&self) -> &FileHeaderData { &self.header @@ -48,17 +52,13 @@ impl<'a> File<'a> { &self.id } - pub fn owner(&self) -> &'a Module<'a> { - self.owning_module - } - pub fn matches_with(&self, r: &Regex) -> bool { r.is_match(&self.data[..]) || self.header.matches_with(r) } } -impl<'a> Display for File<'a> { +impl Display for File { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { write!(fmt, @@ -66,7 +66,7 @@ impl<'a> Display for File<'a> { FileID: '{:?}' Header: '{:?}' Data : '{:?}'", - self.owning_module, + self.owning_module_name, self.header, self.data, self.id); @@ -75,7 +75,7 @@ impl<'a> Display for File<'a> { } -impl<'a> Debug for File<'a> { +impl Debug for File { fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { write!(fmt, @@ -83,7 +83,7 @@ impl<'a> Debug for File<'a> { FileID: '{:?}' Header: '{:?}' Data : '{:?}'", - self.owning_module, + self.owning_module_name, self.header, self.data, self.id); diff --git a/src/storage/mod.rs b/src/storage/mod.rs index c42d2da5..c278e6f6 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -14,23 +14,25 @@ use storage::file::hash::FileHash; use storage::parser::{FileHeaderParser, Parser, ParserError}; use storage::file::header::data::FileHeaderData; -type Cache<'a> = HashMap>>; +type Cache = HashMap>; -pub struct Store<'a> { - cache : RefCell>, +pub struct Store { + cache : RefCell, } -impl<'a> Store<'a> { +impl Store { - pub fn new() -> Store<'a> { + pub fn new() -> Store { Store { cache: RefCell::new(HashMap::new()), } } - pub fn new_file(&self, module: &'a Module<'a>) -> File<'a> { + pub fn new_file(&self, module: &Module) + -> &RefCell + { let f = File { - owning_module: module, + owning_module_name: module.name(), header: FileHeaderData::Null, data: String::from(""), id: self.get_new_file_id(), @@ -39,9 +41,14 @@ impl<'a> Store<'a> { f } - pub fn new_file_from_parser_result(&self, module: &'a Module<'a>, id: FileID, header: FileHeaderData, data: String) -> File<'a> { + pub fn new_file_from_parser_result(&self, + module: &Module, + id: FileID, + header: FileHeaderData, + data: String) -> File + { let f = File { - owning_module: module, + owning_module_name: module.name(), header: header, data: data, id: id, @@ -50,9 +57,9 @@ impl<'a> Store<'a> { f } - pub fn new_file_with_header(&self, module: &'a Module<'a>, h: FileHeaderData) -> File<'a> { + pub fn new_file_with_header(&self, module: &Module, h: FileHeaderData) -> File { let f = File { - owning_module: module, + owning_module_name: module.name(), header: h, data: String::from(""), id: self.get_new_file_id(), @@ -61,9 +68,9 @@ impl<'a> Store<'a> { f } - pub fn new_file_with_data(&self, module: &'a Module<'a>, d: String) -> File<'a> { + pub fn new_file_with_data(&self, module: &Module, d: String) -> File { let f = File { - owning_module: module, + owning_module_name: module.name(), header: FileHeaderData::Null, data: d, id: self.get_new_file_id(), @@ -72,9 +79,9 @@ impl<'a> Store<'a> { f } - pub fn new_file_with_content(&self, module: &'a Module<'a>, h: FileHeaderData, d: String) -> File<'a> { + pub fn new_file_with_content(&self, module: &Module, h: FileHeaderData, d: String) -> File { let f = File { - owning_module: module, + owning_module_name: module.name(), header: h, data: d, id: self.get_new_file_id(), diff --git a/src/ui/file.rs b/src/ui/file.rs index 85168421..114e5c83 100644 --- a/src/ui/file.rs +++ b/src/ui/file.rs @@ -14,7 +14,7 @@ pub trait FilePrinter { /* * Print a list of files */ - fn print_files<'a, I: Iterator>>(&self, files: I) { + fn print_files>(&self, files: I) { for file in files { self.print_file(&file); } @@ -88,7 +88,7 @@ impl FilePrinter for TablePrinter { self.sp.print_file(f); } - fn print_files<'a, I: Iterator>>(&self, files: I) { + fn print_files>(&self, files: I) { use prettytable::Table; use prettytable::row::Row; use prettytable::cell::Cell; @@ -103,7 +103,7 @@ impl FilePrinter for TablePrinter { debug!("Printing file: {:?}", file); i += 1; let cell_i = Cell::new(&format!("{}", i)[..]); - let cell_o = Cell::new(&format!("{}", file.owner().name())[..]); + let cell_o = Cell::new(&format!("{}", file.owner_name())[..]); let id : String = file.id().clone().into(); let cell_id = Cell::new(&id[..]);