mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
simplify
This commit is contained in:
parent
bd1f5ba222
commit
f874d372bb
1 changed files with 19 additions and 23 deletions
|
@ -30,6 +30,25 @@ pub trait AstNode:
|
|||
fn syntax(&self) -> &SyntaxNode;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AstChildren<'a, N> {
|
||||
inner: SyntaxNodeChildren<'a>,
|
||||
ph: PhantomData<N>,
|
||||
}
|
||||
|
||||
impl<'a, N> AstChildren<'a, N> {
|
||||
fn new(parent: &'a SyntaxNode) -> Self {
|
||||
AstChildren { inner: parent.children(), ph: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
|
||||
type Item = &'a N;
|
||||
fn next(&mut self) -> Option<&'a N> {
|
||||
self.inner.by_ref().find_map(N::cast)
|
||||
}
|
||||
}
|
||||
|
||||
impl Attr {
|
||||
pub fn is_inner(&self) -> bool {
|
||||
let tt = match self.value() {
|
||||
|
@ -331,29 +350,6 @@ fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> {
|
|||
AstChildren::new(parent.syntax())
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AstChildren<'a, N> {
|
||||
inner: SyntaxNodeChildren<'a>,
|
||||
ph: PhantomData<N>,
|
||||
}
|
||||
|
||||
impl<'a, N> AstChildren<'a, N> {
|
||||
fn new(parent: &'a SyntaxNode) -> Self {
|
||||
AstChildren { inner: parent.children(), ph: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> {
|
||||
type Item = &'a N;
|
||||
fn next(&mut self) -> Option<&'a N> {
|
||||
loop {
|
||||
if let Some(n) = N::cast(self.inner.next()?) {
|
||||
return Some(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum StructFlavor<'a> {
|
||||
Tuple(&'a PosFieldDefList),
|
||||
|
|
Loading…
Reference in a new issue