Move collection filter to new module

This commit is contained in:
Matthias Beyer 2018-04-29 11:09:59 +02:00
parent eb20a9d881
commit 74c982984c
2 changed files with 49 additions and 17 deletions

View file

@ -0,0 +1,45 @@
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; version
// 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
use filters::filter::Filter;
use libimagstore::storeid::StoreId;
pub struct IsInCollectionsFilter<'a, A>(Option<A>, ::std::marker::PhantomData<&'a str>)
where A: AsRef<[&'a str]>;
impl<'a, A> IsInCollectionsFilter<'a, A>
where A: AsRef<[&'a str]>
{
pub fn new(collections: Option<A>) -> Self {
IsInCollectionsFilter(collections, ::std::marker::PhantomData)
}
}
impl<'a, A> Filter<StoreId> for IsInCollectionsFilter<'a, A>
where A: AsRef<[&'a str]> + 'a
{
fn filter(&self, sid: &StoreId) -> bool {
match self.0 {
Some(ref colls) => sid.is_in_collection(colls),
None => true,
}
}
}

View file

@ -48,25 +48,12 @@ use libimagerror::trace::MapErrTrace;
use libimagerror::iter::TraceIterator; use libimagerror::iter::TraceIterator;
use libimagerror::exit::ExitUnwrap; use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode; use libimagerror::io::ToExitCode;
use libimagstore::storeid::StoreId;
mod id_filters;
mod ui; mod ui;
use ui::build_ui; use ui::build_ui;
use id_filters::IsInCollectionsFilter;
pub struct IsInCollectionsFilter<'a, A>(Option<A>, ::std::marker::PhantomData<&'a str>)
where A: AsRef<[&'a str]>;
impl<'a, A> Filter<StoreId> for IsInCollectionsFilter<'a, A>
where A: AsRef<[&'a str]> + 'a
{
fn filter(&self, sid: &StoreId) -> bool {
match self.0 {
Some(ref colls) => sid.is_in_collection(colls),
None => true,
}
}
}
fn main() { fn main() {
let version = make_imag_version!(); let version = make_imag_version!();
@ -82,7 +69,7 @@ fn main() {
.values_of("in-collection-filter") .values_of("in-collection-filter")
.map(|v| v.collect::<Vec<&str>>()); .map(|v| v.collect::<Vec<&str>>());
let collection_filter = IsInCollectionsFilter(values, ::std::marker::PhantomData); let collection_filter = IsInCollectionsFilter::new(values);
rt.store() rt.store()
.entries() .entries()