From 74c982984c00069ca35426d42d722c940766450c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 29 Apr 2018 11:09:59 +0200 Subject: [PATCH] Move collection filter to new module --- bin/core/imag-ids/src/id_filters.rs | 45 +++++++++++++++++++++++++++++ bin/core/imag-ids/src/main.rs | 21 +++----------- 2 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 bin/core/imag-ids/src/id_filters.rs diff --git a/bin/core/imag-ids/src/id_filters.rs b/bin/core/imag-ids/src/id_filters.rs new file mode 100644 index 00000000..966d7589 --- /dev/null +++ b/bin/core/imag-ids/src/id_filters.rs @@ -0,0 +1,45 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2018 Matthias Beyer 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, ::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) -> Self { + IsInCollectionsFilter(collections, ::std::marker::PhantomData) + } +} + +impl<'a, A> Filter 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, + } + } +} + diff --git a/bin/core/imag-ids/src/main.rs b/bin/core/imag-ids/src/main.rs index 240a03ea..2af2b4d3 100644 --- a/bin/core/imag-ids/src/main.rs +++ b/bin/core/imag-ids/src/main.rs @@ -48,25 +48,12 @@ use libimagerror::trace::MapErrTrace; use libimagerror::iter::TraceIterator; use libimagerror::exit::ExitUnwrap; use libimagerror::io::ToExitCode; -use libimagstore::storeid::StoreId; +mod id_filters; mod ui; + use ui::build_ui; - - -pub struct IsInCollectionsFilter<'a, A>(Option, ::std::marker::PhantomData<&'a str>) - where A: AsRef<[&'a str]>; - -impl<'a, A> Filter 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, - } - } -} +use id_filters::IsInCollectionsFilter; fn main() { let version = make_imag_version!(); @@ -82,7 +69,7 @@ fn main() { .values_of("in-collection-filter") .map(|v| v.collect::>()); - let collection_filter = IsInCollectionsFilter(values, ::std::marker::PhantomData); + let collection_filter = IsInCollectionsFilter::new(values); rt.store() .entries()