Save only module name in File, not whole module
This commit is contained in:
parent
f774effabb
commit
470f1b1378
3 changed files with 39 additions and 32 deletions
|
@ -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);
|
||||
|
|
|
@ -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<FileID, RefCell<File<'a>>>;
|
||||
type Cache = HashMap<FileID, RefCell<File>>;
|
||||
|
||||
pub struct Store<'a> {
|
||||
cache : RefCell<Cache<'a>>,
|
||||
pub struct Store {
|
||||
cache : RefCell<Cache>,
|
||||
}
|
||||
|
||||
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<File>
|
||||
{
|
||||
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(),
|
||||
|
|
|
@ -14,7 +14,7 @@ pub trait FilePrinter {
|
|||
/*
|
||||
* Print a list of files
|
||||
*/
|
||||
fn print_files<'a, I: Iterator<Item = File<'a>>>(&self, files: I) {
|
||||
fn print_files<I: Iterator<Item = File>>(&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<Item = File<'a>>>(&self, files: I) {
|
||||
fn print_files<I: Iterator<Item = File>>(&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[..]);
|
||||
|
|
Loading…
Reference in a new issue