Move filtering to options object, too

I'd like to have as few public methods on it as possible.
This commit is contained in:
Ben S 2014-05-26 12:46:51 +01:00
parent 1dbe20c8c5
commit 573765b62b
2 changed files with 7 additions and 5 deletions

4
exa.rs
View File

@ -43,11 +43,11 @@ fn exa(options: &Options, path: Path) {
Err(e) => fail!("readdir: {}", e), Err(e) => fail!("readdir: {}", e),
}; };
let files: Vec<File> = options.transform_files(paths.iter().map(|path| File::from_path(path)).collect()); let unordered_files: Vec<File> = paths.iter().map(|path| File::from_path(path)).collect();
let files: Vec<&File> = options.transform_files(&unordered_files);
let columns = options.columns(); let columns = options.columns();
let table: Vec<Vec<String>> = files.iter() let table: Vec<Vec<String>> = files.iter()
.filter(|&f| options.show(f))
.map(|f| columns.iter().map(|c| f.display(c)).collect()) .map(|f| columns.iter().map(|c| f.display(c)).collect())
.collect(); .collect();

View File

@ -45,7 +45,7 @@ impl Options {
} }
} }
pub fn show(&self, f: &File) -> bool { fn show(&self, f: &File) -> bool {
if self.showInvisibles { if self.showInvisibles {
true true
} else { } else {
@ -53,8 +53,10 @@ impl Options {
} }
} }
pub fn transform_files<'a>(&self, unordered_files: Vec<File<'a>>) -> Vec<File<'a>> { pub fn transform_files<'a>(&self, unordered_files: &'a Vec<File<'a>>) -> Vec<&'a File<'a>> {
let mut files = unordered_files.clone(); let mut files: Vec<&'a File<'a>> = unordered_files.iter()
.filter(|&f| self.show(f))
.collect();
match self.sortField { match self.sortField {
Name => files.sort_by(|a, b| a.name.cmp(&b.name)), Name => files.sort_by(|a, b| a.name.cmp(&b.name)),