File: Return inner contents as references, not cloned

This commit is contained in:
Matthias Beyer 2015-12-27 23:26:08 +01:00
parent 030b5fc888
commit f774effabb
2 changed files with 8 additions and 8 deletions

View File

@ -32,20 +32,20 @@ pub struct File<'a> {
impl<'a> File<'a> { impl<'a> File<'a> {
pub fn header(&self) -> FileHeaderData { pub fn header(&self) -> &FileHeaderData {
self.header.clone() &self.header
} }
pub fn data(&self) -> String { pub fn data(&self) -> &String {
self.data.clone() &self.data
} }
pub fn contents(&self) -> (FileHeaderData, String) { pub fn contents(&self) -> (&FileHeaderData, &String) {
(self.header(), self.data()) (self.header(), self.data())
} }
pub fn id(&self) -> FileID { pub fn id(&self) -> &FileID {
self.id.clone() &self.id
} }
pub fn owner(&self) -> &'a Module<'a> { pub fn owner(&self) -> &'a Module<'a> {

View File

@ -105,7 +105,7 @@ impl FilePrinter for TablePrinter {
let cell_i = Cell::new(&format!("{}", i)[..]); 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().into(); let id : String = file.id().clone().into();
let cell_id = Cell::new(&id[..]); let cell_id = Cell::new(&id[..]);
let row = Row::new(vec![cell_i, cell_o, cell_id]); let row = Row::new(vec![cell_i, cell_o, cell_id]);
tab.add_row(row); tab.add_row(row);