Merge pull request #496 from matthiasbeyer/libimagentrylist/generic-core

libimagentrylist: Make CoreLister generic
This commit is contained in:
Matthias Beyer 2016-07-05 09:00:19 +02:00 committed by GitHub
commit 1211a99775
2 changed files with 8 additions and 7 deletions

View file

@ -7,6 +7,7 @@ use libimagdiary::error::DiaryErrorKind as DEK;
use libimagentrylist::listers::core::CoreLister;
use libimagentrylist::lister::Lister;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
use libimagstore::storeid::StoreId;
use libimagerror::trace::trace_error;
@ -41,7 +42,7 @@ pub fn list(rt: &Runtime) {
let base = rt.store().path();
CoreLister::new(&move |e| location_to_listing_string(e.get_location(), base))
CoreLister::new(&move |e: &Entry| location_to_listing_string(e.get_location(), base))
.list(es) // TODO: Do not ignore non-ok()s
.map_err(|e| DE::new(DEK::IOError, Some(Box::new(e))))
})

View file

@ -7,21 +7,21 @@ use result::Result;
use libimagstore::store::FileLockEntry;
use libimagstore::store::Entry;
pub struct CoreLister<'a> {
lister: &'a Fn(&Entry) -> String,
pub struct CoreLister<T: Fn(&Entry) -> String> {
lister: Box<T>,
}
impl<'a> CoreLister<'a> {
impl<T: Fn(&Entry) -> String> CoreLister<T> {
pub fn new(lister: &'a Fn(&Entry) -> String) -> CoreLister<'a> {
pub fn new(lister: T) -> CoreLister<T> {
CoreLister {
lister: lister,
lister: Box::new(lister),
}
}
}
impl<'a> Lister for CoreLister<'a> {
impl<T: Fn(&Entry) -> String> Lister for CoreLister<T> {
fn list<'b, I: Iterator<Item = FileLockEntry<'b>>>(&self, entries: I) -> Result<()> {
use error::ListError as LE;