From 199e3b73c712a74e36bbb75eebf9e9418f1b1341 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Aug 2018 14:45:56 +0300 Subject: fields are part of the structure --- crates/libsyntax2/src/ast/generated.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2/src/ast') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 80670ce71..1ec05c950 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -249,6 +249,25 @@ impl AstNode for NameRef { impl NameRef {} +// NamedField +#[derive(Debug, Clone, Copy)] +pub struct NamedField> { + syntax: SyntaxNode, +} + +impl AstNode for NamedField { + fn cast(syntax: SyntaxNode) -> Option { + match syntax.kind() { + NAMED_FIELD => Some(NamedField { syntax }), + _ => None, + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ast::NameOwner for NamedField {} +impl NamedField {} + // NeverType #[derive(Debug, Clone, Copy)] pub struct NeverType> { @@ -436,7 +455,13 @@ impl AstNode for StructDef { } impl ast::NameOwner for StructDef {} -impl StructDef {} +impl StructDef { + pub fn fields<'a>(&'a self) -> impl Iterator> + 'a { + self.syntax() + .children() + .filter_map(NamedField::cast) + } +} // TraitDef #[derive(Debug, Clone, Copy)] -- cgit v1.2.3