mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +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;
|
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 {
|
impl Attr {
|
||||||
pub fn is_inner(&self) -> bool {
|
pub fn is_inner(&self) -> bool {
|
||||||
let tt = match self.value() {
|
let tt = match self.value() {
|
||||||
|
@ -331,29 +350,6 @@ fn children<P: AstNode, C: AstNode>(parent: &P) -> AstChildren<C> {
|
||||||
AstChildren::new(parent.syntax())
|
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum StructFlavor<'a> {
|
pub enum StructFlavor<'a> {
|
||||||
Tuple(&'a PosFieldDefList),
|
Tuple(&'a PosFieldDefList),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue