Add LineLister

This commit is contained in:
Matthias Beyer 2016-03-26 15:27:19 +01:00
parent 5fe843e5d6
commit fdc7e2c391
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,40 @@
use std::io::stdout;
use std::io::Write;
use std::ops::Deref;
use lister::Lister;
use result::Result;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Entry;
pub struct LineLister<'a> {
lister: &'a Fn(&Entry) -> String,
}
impl<'a> LineLister<'a> {
pub fn new(lister: &'a Fn(&Entry) -> String) -> LineLister<'a> {
LineLister {
lister: lister,
}
}
}
impl<'a> Lister for LineLister<'a> {
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
use error::ListError as LE;
use error::ListErrorKind as LEK;
entries.fold(Ok(()), |accu, entry| {
accu.and_then(|_| {
write!(stdout(), "{:?}\n", (self.lister)(entry.deref()))
.map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
})
})
}
}

View file

@ -1 +1,2 @@
pub mod line;
pub mod path;