Skip to main content

AstNode

Trait AstNode 

Source
pub trait AstNode: Sized {
    // Required methods
    fn can_cast(kind: SyntaxKind) -> bool;
    fn cast(syntax: SyntaxNode) -> Option<Self>;
    fn syntax(&self) -> &SyntaxNode;
}
Expand description

Typed wrapper around a SyntaxNode of a specific SyntaxKind.

Required Methods§

Source

fn can_cast(kind: SyntaxKind) -> bool

Returns true iff kind is the wrapper’s expected node kind. Used by cast and by enum dispatch.

Source

fn cast(syntax: SyntaxNode) -> Option<Self>

Wrap syntax if its kind matches; otherwise None.

Source

fn syntax(&self) -> &SyntaxNode

The underlying CST node. text() reproduces the original bytes; children() / children_with_tokens() walk the tree.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§