diff options
author | Aleksey Kladov <[email protected]> | 2020-04-09 12:00:09 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-09 12:00:09 +0100 |
commit | 689661c95968cb438f8bd1f10ce0ee096287741b (patch) | |
tree | a974bfe4160a0cb0d49146b239d68cdb99a6566d /crates/ra_syntax/src/ast.rs | |
parent | 60f4d7bd8c0ecb9f23557464e824140a2be8f41a (diff) |
Scale back to only two traits
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index c81b68d3e..e1ebd5b92 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -64,6 +64,22 @@ pub trait AstToken { | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | mod support { | ||
68 | use super::{AstChildren, AstNode, AstToken, SyntaxNode}; | ||
69 | |||
70 | pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> { | ||
71 | parent.children().find_map(N::cast) | ||
72 | } | ||
73 | |||
74 | pub(super) fn children<N: AstNode>(parent: &SyntaxNode) -> AstChildren<N> { | ||
75 | AstChildren::new(parent) | ||
76 | } | ||
77 | |||
78 | pub(super) fn token<T: AstToken>(parent: &SyntaxNode) -> Option<T> { | ||
79 | parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast) | ||
80 | } | ||
81 | } | ||
82 | |||
67 | /// An iterator over `SyntaxNode` children of a particular AST type. | 83 | /// An iterator over `SyntaxNode` children of a particular AST type. |
68 | #[derive(Debug, Clone)] | 84 | #[derive(Debug, Clone)] |
69 | pub struct AstChildren<N> { | 85 | pub struct AstChildren<N> { |