aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-02 08:09:52 +0100
committerAleksey Kladov <[email protected]>2019-04-02 08:09:52 +0100
commitf874d372bb7f756dfa6ebc22ca838657c8ff1539 (patch)
treeff577c9df38b71346dfb1bed4334ce32ec5c7d7a
parentbd1f5ba222a1f5a44c20a9fcb70c3785a3758b20 (diff)
simplify
-rw-r--r--crates/ra_syntax/src/ast.rs42
1 files changed, 19 insertions, 23 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 3e81fa990..9950ab12d 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -30,6 +30,25 @@ pub trait AstNode:
30 fn syntax(&self) -> &SyntaxNode; 30 fn syntax(&self) -> &SyntaxNode;
31} 31}
32 32
33#[derive(Debug)]
34pub struct AstChildren<'a, N> {
35 inner: SyntaxNodeChildren<'a>,
36 ph: PhantomData<N>,
37}
38
39impl<'a, N> AstChildren<'a, N> {
40 fn new(parent: &'a SyntaxNode) -> Self {
41 AstChildren { inner: parent.children(), ph: PhantomData }
42 }
43}
44
45impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
46 type Item = &'a N;
47 fn next(&mut self) -> Option<&'a N> {
48 self.inner.by_ref().find_map(N::cast)
49 }
50}
51
33impl Attr { 52impl Attr {
34 pub fn is_inner(&self) -> bool { 53 pub fn is_inner(&self) -> bool {
35 let tt = match self.value() { 54 let tt = match self.value() {
@@ -331,29 +350,6 @@ fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> {
331 AstChildren::new(parent.syntax()) 350 AstChildren::new(parent.syntax())
332} 351}
333 352
334#[derive(Debug)]
335pub struct AstChildren<'a, N> {
336 inner: SyntaxNodeChildren<'a>,
337 ph: PhantomData<N>,
338}
339
340impl<'a, N> AstChildren<'a, N> {
341 fn new(parent: &'a SyntaxNode) -> Self {
342 AstChildren { inner: parent.children(), ph: PhantomData }
343 }
344}
345
346impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
347 type Item = &'a N;
348 fn next(&mut self) -> Option<&'a N> {
349 loop {
350 if let Some(n) = N::cast(self.inner.next()?) {
351 return Some(n);
352 }
353 }
354 }
355}
356
357#[derive(Debug, Clone, PartialEq, Eq)] 353#[derive(Debug, Clone, PartialEq, Eq)]
358pub enum StructFlavor<'a> { 354pub enum StructFlavor<'a> {
359 Tuple(&'a PosFieldDefList), 355 Tuple(&'a PosFieldDefList),