Get rid of ItemOrMacro

This commit is contained in:
Aleksey Kladov 2020-03-26 16:10:01 +01:00
parent 539e597743
commit db34abeb85
7 changed files with 21 additions and 41 deletions

View file

@ -6,8 +6,7 @@ use itertools::Itertools;
use crate::{
ast::{self, child_opt, children, AstChildren, AstNode, AstToken},
match_ast,
syntax_node::{SyntaxElementChildren, SyntaxNodeChildren},
syntax_node::SyntaxElementChildren,
};
pub trait TypeAscriptionOwner: AstNode {
@ -46,38 +45,10 @@ pub trait FnDefOwner: AstNode {
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ItemOrMacro {
Item(ast::ModuleItem),
Macro(ast::MacroCall),
}
pub trait ModuleItemOwner: AstNode {
fn items(&self) -> AstChildren<ast::ModuleItem> {
children(self)
}
fn items_with_macros(&self) -> ItemOrMacroIter {
ItemOrMacroIter(self.syntax().children())
}
}
#[derive(Debug)]
pub struct ItemOrMacroIter(SyntaxNodeChildren);
impl Iterator for ItemOrMacroIter {
type Item = ItemOrMacro;
fn next(&mut self) -> Option<ItemOrMacro> {
loop {
let n = self.0.next()?;
match_ast! {
match n {
ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) },
ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) },
_ => {},
}
}
}
}
}
pub trait TypeParamsOwner: AstNode {