support upcastig in AST enum

This commit is contained in:
Aleksey Kladov 2019-02-24 16:57:05 +03:00
parent c110e72a11
commit 666303faf3
2 changed files with 407 additions and 0 deletions

View file

@ -38,6 +38,15 @@ pub enum {{ node }}Kind<'a> {
{%- endfor %}
}
{%- for kind in methods.enum %}
impl<'a> From<&'a {{ kind }}> for &'a {{ node }} {
fn from(n: &'a {{ kind }}) -> &'a {{ node }} {
{{ node }}::cast(&n.syntax).unwrap()
}
}
{%- endfor %}
impl AstNode for {{ node }} {
fn cast(syntax: &SyntaxNode) -> Option<&Self> {
match syntax.kind() {