Implement iterator for context.

This commit is contained in:
Tom Alexander
2023-09-02 20:46:17 -04:00
parent 22e9bc991f
commit 0d728510d7
9 changed files with 102 additions and 39 deletions

View File

@@ -27,6 +27,10 @@ impl<'parent, T> List<'parent, T> {
pub fn iter(&self) -> Iter<'_, T> {
Iter { next: Some(self) }
}
pub fn iter_list(&self) -> IterList<'_, T> {
Iter { next: Some(self) }
}
}
pub trait ListType<'parent, T> {
@@ -64,3 +68,17 @@ impl<'a, T> Iterator for Iter<'a, T> {
ret
}
}
pub struct IterList<'a, T> {
next: Link<'a, T>,
}
impl<'a, T> Iterator for IterList<'a, T> {
type Item = &'a List<'a, T>;
fn next(&mut self) -> Option<Self::Item> {
let ret = self.next;
self.next = self.next.map(|this| this.get_parent()).flatten();
ret
}
}