ui: Change to take Rc<RefCell<File>> instead of File
This commit is contained in:
parent
c8a0c1168d
commit
74aab89fbb
1 changed files with 14 additions and 11 deletions
|
@ -1,4 +1,7 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
use storage::file::File;
|
use storage::file::File;
|
||||||
|
|
||||||
|
@ -9,14 +12,14 @@ pub trait FilePrinter {
|
||||||
/*
|
/*
|
||||||
* Print a single file
|
* Print a single file
|
||||||
*/
|
*/
|
||||||
fn print_file(&self, &File);
|
fn print_file(&self, Rc<RefCell<File>>);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Print a list of files
|
* Print a list of files
|
||||||
*/
|
*/
|
||||||
fn print_files<I: Iterator<Item = File>>(&self, files: I) {
|
fn print_files<I: Iterator<Item = Rc<RefCell<File>>>>(&self, files: I) {
|
||||||
for file in files {
|
for file in files {
|
||||||
self.print_file(&file);
|
self.print_file(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +37,7 @@ impl FilePrinter for DebugPrinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_file(&self, f: &File) {
|
fn print_file(&self, f: Rc<RefCell<File>>) {
|
||||||
if self.debug {
|
if self.debug {
|
||||||
debug!("[DebugPrinter] ->\n{:?}", f);
|
debug!("[DebugPrinter] ->\n{:?}", f);
|
||||||
}
|
}
|
||||||
|
@ -56,13 +59,13 @@ impl FilePrinter for SimplePrinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_file(&self, f: &File) {
|
fn print_file(&self, f: Rc<RefCell<File>>) {
|
||||||
if self.debug {
|
if self.debug {
|
||||||
debug!("{:?}", f);
|
debug!("{:?}", f);
|
||||||
} else if self.verbose {
|
} else if self.verbose {
|
||||||
info!("{}", f);
|
info!("{}", &*f.deref().borrow());
|
||||||
} else {
|
} else {
|
||||||
info!("[File]: {}", f.id());
|
info!("[File]: {}", f.deref().borrow().id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +87,11 @@ impl FilePrinter for TablePrinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_file(&self, f: &File) {
|
fn print_file(&self, f: Rc<RefCell<File>>) {
|
||||||
self.sp.print_file(f);
|
self.sp.print_file(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_files<I: Iterator<Item = File>>(&self, files: I) {
|
fn print_files<I: Iterator<Item = Rc<RefCell<File>>>>(&self, files: I) {
|
||||||
use prettytable::Table;
|
use prettytable::Table;
|
||||||
use prettytable::row::Row;
|
use prettytable::row::Row;
|
||||||
use prettytable::cell::Cell;
|
use prettytable::cell::Cell;
|
||||||
|
@ -103,9 +106,9 @@ impl FilePrinter for TablePrinter {
|
||||||
debug!("Printing file: {:?}", file);
|
debug!("Printing file: {:?}", file);
|
||||||
i += 1;
|
i += 1;
|
||||||
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.deref().borrow().owner_name())[..]);
|
||||||
|
|
||||||
let id : String = file.id().clone().into();
|
let id : String = file.deref().borrow().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);
|
||||||
|
|
Loading…
Reference in a new issue