SequenceView: add .iter()
This commit is contained in:
parent
fe4707e7b2
commit
bd1572c632
1 changed files with 34 additions and 0 deletions
|
@ -19,6 +19,40 @@ pub trait SequenceView : View<Msg = usize> {
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
pub trait SequenceViewExt : SequenceView {
|
||||||
|
fn iter<'a>(&'a self) -> SequenceViewIter<'a, Self> {
|
||||||
|
SequenceViewIter {
|
||||||
|
view: self,
|
||||||
|
cur: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<V: SequenceView + ?Sized> SequenceViewExt for V {}
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
|
pub struct SequenceViewIter<'a, V>
|
||||||
|
where V: SequenceView + ?Sized
|
||||||
|
{
|
||||||
|
view: &'a V,
|
||||||
|
cur: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, V> Iterator for SequenceViewIter<'a, V>
|
||||||
|
where V: SequenceView + ?Sized
|
||||||
|
{
|
||||||
|
type Item = V::Item;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let i = self.cur;
|
||||||
|
self.cur += 1;
|
||||||
|
self.view.get(&i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
ops::{Deref}
|
ops::{Deref}
|
||||||
|
|
Loading…
Reference in a new issue