mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
fields are part of the structure
This commit is contained in:
parent
1141d448d9
commit
199e3b73c7
4 changed files with 44 additions and 10 deletions
|
@ -249,6 +249,25 @@ impl<R: TreeRoot> AstNode<R> for NameRef<R> {
|
|||
|
||||
impl<R: TreeRoot> NameRef<R> {}
|
||||
|
||||
// NamedField
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NamedField<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
syntax: SyntaxNode<R>,
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> AstNode<R> for NamedField<R> {
|
||||
fn cast(syntax: SyntaxNode<R>) -> Option<Self> {
|
||||
match syntax.kind() {
|
||||
NAMED_FIELD => Some(NamedField { syntax }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode<R> { &self.syntax }
|
||||
}
|
||||
|
||||
impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {}
|
||||
impl<R: TreeRoot> NamedField<R> {}
|
||||
|
||||
// NeverType
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NeverType<R: TreeRoot = Arc<SyntaxRoot>> {
|
||||
|
@ -436,7 +455,13 @@ impl<R: TreeRoot> AstNode<R> for StructDef<R> {
|
|||
}
|
||||
|
||||
impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {}
|
||||
impl<R: TreeRoot> StructDef<R> {}
|
||||
impl<R: TreeRoot> StructDef<R> {
|
||||
pub fn fields<'a>(&'a self) -> impl Iterator<Item = NamedField<R>> + 'a {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(NamedField::cast)
|
||||
}
|
||||
}
|
||||
|
||||
// TraitDef
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue