Use From to get an owned AST

This commit is contained in:
Aleksey Kladov 2018-11-01 13:41:04 +03:00
parent 3ec9f958b3
commit d685a9b564
3 changed files with 701 additions and 402 deletions

View file

@ -17,15 +17,18 @@ use crate::{
pub struct {{ node }}Node(SyntaxNode);
impl {{ node }}Node {
pub fn new(ast: {{ node }}) -> {{ node }}Node {
let syntax = ast.syntax().owned();
{{ node }}Node(syntax)
}
pub fn ast(&self) -> {{ node }} {
{{ node }}::cast(self.0.borrowed()).unwrap()
}
}
impl<'a> From<{{ node }}<'a>> for {{ node }}Node {
fn from(ast: {{ node}}<'a>) -> {{ node }}Node {
let syntax = ast.syntax().owned();
{{ node }}Node(syntax)
}
}
{%- if methods.enum %}
#[derive(Debug, Clone, Copy)]
pub enum {{ node }}<'a> {