summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-29 11:09:59 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-05-02 20:42:56 +0200
commit74c982984c00069ca35426d42d722c940766450c (patch)
tree766768f5feb69104f39cd4edd0e0a291805f0414 /bin
parenteb20a9d881eb801ff794d7b0d20e2a012d2f9094 (diff)
Move collection filter to new module
Diffstat (limited to 'bin')
-rw-r--r--bin/core/imag-ids/src/id_filters.rs45
-rw-r--r--bin/core/imag-ids/src/main.rs21
2 files changed, 49 insertions, 17 deletions
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 <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,
+ }
+ }
+}
+
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<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,
- }
- }
-}
+use ui::build_ui;
+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::<Vec<&str>>());
- let collection_filter = IsInCollectionsFilter(values, ::std::marker::PhantomData);
+ let collection_filter = IsInCollectionsFilter::new(values);
rt.store()
.entries()