From 3068af79ffd23656ff2d46ac92d9192ce6c813fb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 31 Oct 2018 10:27:53 +0300 Subject: Introduce owned ast nodes ast::FooNode is an owned 'static counterpart to ast::Foo<'a> --- crates/ra_syntax/src/ast/generated.rs.tera | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast/generated.rs.tera') diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index e1404deac..c61c3e80b 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera @@ -7,11 +7,25 @@ the below applies to the result of this template use crate::{ ast, - SyntaxNodeRef, AstNode, + SyntaxNode, SyntaxNodeRef, AstNode, SyntaxKind::*, }; {% for node, methods in ast %} // {{ node }} + +#[derive(Debug, Clone)] +pub struct {{ node }}Node(SyntaxNode); + +impl {{ node }}Node { + pub fn new(&self, ast: {{ node }}) -> {{ node }}Node { + let syntax = ast.syntax().owned(); + {{ node }}Node(syntax) + } + pub fn ast(&self) -> {{ node }} { + {{ node }}::cast(self.0.borrowed()).unwrap() + } +} + {%- if methods.enum %} #[derive(Debug, Clone, Copy)] pub enum {{ node }}<'a> { -- cgit v1.2.3