Implement empty iterator for types with no ast node children.
This commit is contained in:
30
src/iter/macros.rs
Normal file
30
src/iter/macros.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
/// Create iterators for ast nodes where it only has to iterate over children
|
||||
macro_rules! simple_iter {
|
||||
($astnodetype:ty, $itertype:ident, $innertype:ty) => {
|
||||
pub struct $itertype<'r, 's> {
|
||||
next: $innertype,
|
||||
}
|
||||
|
||||
impl<'r, 's> Iterator for $itertype<'r, 's> {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.next.next().map(Into::<AstNode>::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, 's> IntoIterator for &'r $astnodetype {
|
||||
type Item = AstNode<'r, 's>;
|
||||
|
||||
type IntoIter = $itertype<'r, 's>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
$itertype {
|
||||
next: self.children.iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use simple_iter;
|
||||
Reference in New Issue
Block a user