Skip to content

Commit 1e27c25

Browse files
committed
Implement FusedIterator for those which already have the property by design.
1 parent cc40ed7 commit 1e27c25

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ macro_rules! axis_iterators {
143143
$i(self.0)
144144
}
145145
}
146+
impl<'a, T: 'a> FusedIterator for $i<'a, T> {}
146147
impl<'a, T: 'a> Iterator for $i<'a, T> {
147148
type Item = NodeRef<'a, T>;
148149
fn next(&mut self) -> Option<Self::Item> {
@@ -186,6 +187,7 @@ impl<'a, T: 'a> Clone for Children<'a, T> {
186187
}
187188
}
188189
}
190+
impl<'a, T: 'a> FusedIterator for Children<'a, T> {}
189191
impl<'a, T: 'a> Iterator for Children<'a, T> {
190192
type Item = NodeRef<'a, T>;
191193
fn next(&mut self) -> Option<Self::Item> {

tests/iter.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ fn ancestors() {
6161
);
6262
}
6363

64+
#[test]
65+
fn ancestors_fused() {
66+
let tree = tree!('a' => { 'b' => { 'c' => { 'd' } } });
67+
let d = tree
68+
.root()
69+
.last_child()
70+
.unwrap()
71+
.last_child()
72+
.unwrap()
73+
.last_child()
74+
.unwrap();
75+
76+
let mut ancestors = d.ancestors();
77+
assert_eq!(ancestors.by_ref().count(), 3);
78+
assert_eq!(ancestors.next(), None);
79+
}
80+
6481
#[test]
6582
fn prev_siblings() {
6683
let tree = tree!('a' => { 'b', 'c', 'd' });
@@ -101,6 +118,16 @@ fn children() {
101118
);
102119
}
103120

121+
#[test]
122+
fn children_fused() {
123+
let tree = tree!('a' => { 'b', 'c', 'd' });
124+
125+
let mut children = tree.root().children();
126+
127+
assert_eq!(children.by_ref().count(), 3);
128+
assert_eq!(children.next(), None);
129+
}
130+
104131
#[test]
105132
fn children_rev() {
106133
let tree = tree!('a' => { 'b', 'c', 'd' });

0 commit comments

Comments
 (0)