diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-07-15 15:01:45 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2017-07-15 16:39:27 +0200 |
commit | 6d818a3b48fe6046a0607737b3fce6323c4daa5f (patch) | |
tree | 7af3fd53eb1d22c43668f2a0aa58da961ff03511 | |
parent | b88e95f88163d22a8b18262590919fd4818b1392 (diff) |
Add filter module for tag iterators
-rw-r--r-- | libimagentrytimetrack/src/iter/filter.rs | 70 | ||||
-rw-r--r-- | libimagentrytimetrack/src/iter/mod.rs | 1 |
2 files changed, 71 insertions, 0 deletions
diff --git a/libimagentrytimetrack/src/iter/filter.rs b/libimagentrytimetrack/src/iter/filter.rs new file mode 100644 index 00000000..b236c8dd --- /dev/null +++ b/libimagentrytimetrack/src/iter/filter.rs @@ -0,0 +1,70 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 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 error::TimeTrackError as TTE; +use error::TimeTrackErrorKind as TTEK; +use error::MapErrInto; + +use libimagstore::store::FileLockEntry; +use libimagstore::store::Store; +use libimagstore::storeid::StoreIdIterator; +use libimagerror::into::IntoError; + +use iter::get::GetTimeTrackIter; +use tag::TimeTrackingTag as TTT; +use timetracking::TimeTracking; + +pub struct WithOneOf<'a> { + iter: GetTimeTrackIter<'a>, + allowed_tags: &'a Vec<TTT>, +} + +impl<'a> WithOneOf<'a> { + + pub fn new(iter: GetTimeTrackIter<'a>, allowed_tags: &'a Vec<TTT>) -> WithOneOf<'a> { + WithOneOf { + iter: iter, + allowed_tags: allowed_tags + } + } +} + +impl<'a> Iterator for WithOneOf<'a> { + type Item = Result<FileLockEntry<'a>, TTE>; + + fn next(&mut self) -> Option<Self::Item> { + loop { + match self.iter.next() { + Some(Ok(fle)) => { + match fle.get_timetrack_tag() { + Err(e) => return Some(Err(e)), + Ok(t) => if self.allowed_tags.contains(&t) { + return Some(Ok(fle)) + } else { + // loop + }, + } + }, + Some(Err(e)) => return Some(Err(e)), + None => return None, + } + } + } +} + diff --git a/libimagentrytimetrack/src/iter/mod.rs b/libimagentrytimetrack/src/iter/mod.rs index 22dcea26..d2d78cd9 100644 --- a/libimagentrytimetrack/src/iter/mod.rs +++ b/libimagentrytimetrack/src/iter/mod.rs @@ -18,6 +18,7 @@ // pub mod create; +pub mod filter; pub mod get; pub mod setendtime; pub mod storeid; |