aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/traits.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-26 15:10:01 +0000
committerAleksey Kladov <[email protected]>2020-03-26 15:10:01 +0000
commitdb34abeb8589518896b82f52062b9fab4c2b1352 (patch)
tree3ac357657b2dfa901bc28d35a7934123778dc30a /crates/ra_syntax/src/ast/traits.rs
parent539e597743229b4497491f325a257bef026602c7 (diff)
Get rid of ItemOrMacro
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r--crates/ra_syntax/src/ast/traits.rs31
1 files changed, 1 insertions, 30 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index f8cf1e3eb..576378306 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -6,8 +6,7 @@ use itertools::Itertools;
6 6
7use crate::{ 7use crate::{
8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, 8 ast::{self, child_opt, children, AstChildren, AstNode, AstToken},
9 match_ast, 9 syntax_node::SyntaxElementChildren,
10 syntax_node::{SyntaxElementChildren, SyntaxNodeChildren},
11}; 10};
12 11
13pub trait TypeAscriptionOwner: AstNode { 12pub trait TypeAscriptionOwner: AstNode {
@@ -46,38 +45,10 @@ pub trait FnDefOwner: AstNode {
46 } 45 }
47} 46}
48 47
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub enum ItemOrMacro {
51 Item(ast::ModuleItem),
52 Macro(ast::MacroCall),
53}
54
55pub trait ModuleItemOwner: AstNode { 48pub trait ModuleItemOwner: AstNode {
56 fn items(&self) -> AstChildren<ast::ModuleItem> { 49 fn items(&self) -> AstChildren<ast::ModuleItem> {
57 children(self) 50 children(self)
58 } 51 }
59 fn items_with_macros(&self) -> ItemOrMacroIter {
60 ItemOrMacroIter(self.syntax().children())
61 }
62}
63
64#[derive(Debug)]
65pub struct ItemOrMacroIter(SyntaxNodeChildren);
66
67impl Iterator for ItemOrMacroIter {
68 type Item = ItemOrMacro;
69 fn next(&mut self) -> Option<ItemOrMacro> {
70 loop {
71 let n = self.0.next()?;
72 match_ast! {
73 match n {
74 ast::ModuleItem(it) => { return Some(ItemOrMacro::Item(it)) },
75 ast::MacroCall(it) => { return Some(ItemOrMacro::Macro(it)) },
76 _ => {},
77 }
78 }
79 }
80 }
81} 52}
82 53
83pub trait TypeParamsOwner: AstNode { 54pub trait TypeParamsOwner: AstNode {