rowan::ast

Trait AstNode

Source
pub trait AstNode {
    type Language: Language;

    // Required methods
    fn can_cast(kind: <Self::Language as Language>::Kind) -> bool
       where Self: Sized;
    fn cast(node: SyntaxNode<Self::Language>) -> Option<Self>
       where Self: Sized;
    fn syntax(&self) -> &SyntaxNode<Self::Language>;

    // Provided methods
    fn clone_for_update(&self) -> Self
       where Self: Sized { ... }
    fn clone_subtree(&self) -> Self
       where Self: Sized { ... }
}
Expand description

The main trait to go from untyped SyntaxNode to a typed AST. The conversion itself has zero runtime cost: AST and syntax nodes have exactly the same representation: a pointer to the tree root and a pointer to the node itself.

Required Associated Types§

Required Methods§

Source

fn can_cast(kind: <Self::Language as Language>::Kind) -> bool
where Self: Sized,

Source

fn cast(node: SyntaxNode<Self::Language>) -> Option<Self>
where Self: Sized,

Source

fn syntax(&self) -> &SyntaxNode<Self::Language>

Provided Methods§

Source

fn clone_for_update(&self) -> Self
where Self: Sized,

Source

fn clone_subtree(&self) -> Self
where Self: Sized,

Implementors§

impl AstNode for Attr

impl AstNode for Entry

impl AstNode for Expr

impl AstNode for Param

impl AstNode for Apply

impl AstNode for Assert

impl AstNode for AttrSet

impl AstNode for Attrpath

impl AstNode for BinOp

impl AstNode for Dynamic

impl AstNode for Error

impl AstNode for HasAttr

impl AstNode for Ident

impl AstNode for IfElse

impl AstNode for Inherit

impl AstNode for Interpol

impl AstNode for Lambda

impl AstNode for LetIn

impl AstNode for List

impl AstNode for Literal

impl AstNode for Paren

impl AstNode for PatBind

impl AstNode for PatEntry

impl AstNode for Path

impl AstNode for Pattern

impl AstNode for Root

impl AstNode for Select

impl AstNode for Str

impl AstNode for UnaryOp

impl AstNode for With