imag/lib/domain/libimaghabit/src/iter.rs

73 lines
2.1 KiB
Rust
Raw Normal View History

2017-09-01 18:41:09 +00:00
//
// 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 libimagstore::storeid::StoreIdIterator;
use libimagstore::storeid::StoreId;
2017-11-24 17:55:12 +00:00
use util::IsHabitCheck;
2017-09-01 18:41:09 +00:00
pub struct HabitTemplateStoreIdIterator(StoreIdIterator);
impl Iterator for HabitTemplateStoreIdIterator {
type Item = StoreId;
fn next(&mut self) -> Option<Self::Item> {
while let Some(n) = self.0.next() {
2017-11-24 17:55:12 +00:00
if n.is_habit_template() {
2017-09-01 18:41:09 +00:00
return Some(n)
}
}
None
}
}
impl From<StoreIdIterator> for HabitTemplateStoreIdIterator {
fn from(sii: StoreIdIterator) -> Self {
HabitTemplateStoreIdIterator(sii)
}
}
pub struct HabitInstanceStoreIdIterator(StoreIdIterator);
2017-12-03 20:05:41 +00:00
impl HabitInstanceStoreIdIterator {
pub fn new(sid: StoreIdIterator) -> HabitInstanceStoreIdIterator {
HabitInstanceStoreIdIterator(sid)
}
}
2017-09-01 18:41:09 +00:00
impl Iterator for HabitInstanceStoreIdIterator {
type Item = StoreId;
fn next(&mut self) -> Option<Self::Item> {
while let Some(n) = self.0.next() {
2017-11-24 17:55:12 +00:00
if n.is_habit_instance() {
2017-09-01 18:41:09 +00:00
return Some(n)
}
}
None
}
}
impl From<StoreIdIterator> for HabitInstanceStoreIdIterator {
fn from(sii: StoreIdIterator) -> Self {
HabitInstanceStoreIdIterator(sii)
}
}