Implement iterator for context.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user