Implement ExactSizeIterator for the other node types.

This commit is contained in:
Tom Alexander
2023-10-10 15:27:03 -04:00
parent b7f7876706
commit c578bb45af
2 changed files with 21 additions and 29 deletions

View File

@@ -11,8 +11,15 @@ macro_rules! children_iter {
fn next(&mut self) -> Option<Self::Item> {
self.next.next().map(Into::<AstNode>::into)
}
fn size_hint(&self) -> (usize, Option<usize>) {
let size = self.next.len();
(size, Some(size))
}
}
impl<'r, 's> ExactSizeIterator for $itertype<'r, 's> {}
impl<'r, 's> IntoIterator for &'r $astnodetype {
type Item = AstNode<'r, 's>;
@@ -42,8 +49,14 @@ macro_rules! empty_iter {
fn next(&mut self) -> Option<Self::Item> {
None
}
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}
impl<'r, 's> ExactSizeIterator for $itertype<'r, 's> {}
impl<'r, 's> IntoIterator for &'r $astnodetype {
type Item = AstNode<'r, 's>;