relm4/typed_view/
iterator.rs1use std::any::Any;
2
3use super::{
4 TypedListItem,
5 column::TypedColumnView,
6 grid::{RelmGridItem, TypedGridView},
7 list::{RelmListItem, TypedListView},
8 selection_ext::RelmSelectionExt,
9};
10
11#[derive(Debug)]
12pub struct TypedIterator<'a, T> {
15 pub(super) list: &'a T,
16 pub(super) index: u32,
17}
18
19impl<T, S> Iterator for TypedIterator<'_, TypedColumnView<T, S>>
20where
21 T: Any,
22 S: RelmSelectionExt,
23{
24 type Item = TypedListItem<T>;
25
26 fn next(&mut self) -> Option<Self::Item> {
27 if self.index < self.list.len() {
28 let result = self.list.get(self.index);
29 self.index += 1;
30 result
31 } else {
32 None
33 }
34 }
35}
36
37impl<T, S> Iterator for TypedIterator<'_, TypedGridView<T, S>>
38where
39 T: RelmGridItem + Ord,
40 S: RelmSelectionExt,
41{
42 type Item = TypedListItem<T>;
43
44 fn next(&mut self) -> Option<Self::Item> {
45 if self.index < self.list.len() {
46 let result = self.list.get(self.index);
47 self.index += 1;
48 result
49 } else {
50 None
51 }
52 }
53}
54
55impl<T, S> Iterator for TypedIterator<'_, TypedListView<T, S>>
56where
57 T: RelmListItem,
58 S: RelmSelectionExt,
59{
60 type Item = TypedListItem<T>;
61
62 fn next(&mut self) -> Option<Self::Item> {
63 if self.index < self.list.len() {
64 let result = self.list.get(self.index);
65 self.index += 1;
66 result
67 } else {
68 None
69 }
70 }
71}