aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated.rs.tera
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-11-06 19:08:00 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-11-06 19:08:00 +0000
commit3928255b6f919ca0a0a93393ab7fa3d0ce6df681 (patch)
treefd67f18d5a631a1cbcb84cbe3455713943253fb8 /crates/ra_syntax/src/ast/generated.rs.tera
parent21797bf0efdeafde4148fe02ba4bd11171737872 (diff)
parent7f88fe8790014f4c879ec49de4bfdb823043e16a (diff)
Merge #209
209: Owned nodes r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs.tera')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera38
1 files changed, 20 insertions, 18 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera
index 1321f0def..d4fc6b5bd 100644
--- a/crates/ra_syntax/src/ast/generated.rs.tera
+++ b/crates/ra_syntax/src/ast/generated.rs.tera
@@ -3,32 +3,23 @@ the below applies to the result of this template
3#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run 3#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
4// Do not edit manually 4// Do not edit manually
5 5
6//! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
7//! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
8//! are Arc-based. You can switch between the two variants using `.owned` and
9//! `.borrowed` functions. Most of the code works with borowed mode, and only
10//! this mode has all AST accessors.
11
6#![cfg_attr(rustfmt, rustfmt_skip)] 12#![cfg_attr(rustfmt, rustfmt_skip)]
7 13
8use crate::{ 14use crate::{
9 ast, 15 ast,
10 SyntaxNode, SyntaxNodeRef, AstNode, 16 SyntaxNode, SyntaxNodeRef, AstNode,
17 yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot},
11 SyntaxKind::*, 18 SyntaxKind::*,
12}; 19};
13{% for node, methods in ast %} 20{% for node, methods in ast %}
14// {{ node }} 21// {{ node }}
15 22
16#[derive(Debug, Clone)]
17pub struct {{ node }}Node(SyntaxNode);
18
19impl {{ node }}Node {
20 pub fn ast(&self) -> {{ node }} {
21 {{ node }}::cast(self.0.borrowed()).unwrap()
22 }
23}
24
25impl<'a> From<{{ node }}<'a>> for {{ node }}Node {
26 fn from(ast: {{ node}}<'a>) -> {{ node }}Node {
27 let syntax = ast.syntax().owned();
28 {{ node }}Node(syntax)
29 }
30}
31
32{%- if methods.enum %} 23{%- if methods.enum %}
33#[derive(Debug, Clone, Copy)] 24#[derive(Debug, Clone, Copy)]
34pub enum {{ node }}<'a> { 25pub enum {{ node }}<'a> {
@@ -56,9 +47,10 @@ impl<'a> AstNode<'a> for {{ node }}<'a> {
56} 47}
57{% else %} 48{% else %}
58#[derive(Debug, Clone, Copy)] 49#[derive(Debug, Clone, Copy)]
59pub struct {{ node }}<'a> { 50pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> {
60 syntax: SyntaxNodeRef<'a>, 51 syntax: SyntaxNode<R>,
61} 52}
53pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>;
62 54
63impl<'a> AstNode<'a> for {{ node }}<'a> { 55impl<'a> AstNode<'a> for {{ node }}<'a> {
64 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { 56 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
@@ -69,6 +61,16 @@ impl<'a> AstNode<'a> for {{ node }}<'a> {
69 } 61 }
70 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } 62 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
71} 63}
64
65impl<R: TreeRoot<RaTypes>> {{ node }}Node<R> {
66 pub fn borrowed(&self) -> {{ node }} {
67 {{ node }}Node { syntax: self.syntax.borrowed() }
68 }
69 pub fn owned(&self) -> {{ node }}Node {
70 {{ node }}Node { syntax: self.syntax.owned() }
71 }
72}
73
72{% endif %} 74{% endif %}
73{% if methods.traits -%} 75{% if methods.traits -%}
74{%- for t in methods.traits -%} 76{%- for t in methods.traits -%}