pub trait AstNode: Sized {
// Required methods
fn can_cast(kind: SyntaxKind) -> bool;
fn cast(node: SyntaxNode) -> Option<Self>;
fn syntax(&self) -> &SyntaxNode;
}Expand description
Trait implemented by all typed AST node wrappers.
Provides the ability to check, cast, and unwrap SyntaxNode values into
their strongly-typed AST representations. All implementations are zero-cost:
casting is a simple kind check followed by a newtype wrap.
Required Methods§
Sourcefn can_cast(kind: SyntaxKind) -> bool
fn can_cast(kind: SyntaxKind) -> bool
Returns true if a SyntaxNode with the given kind can be cast to
this AST type.
Sourcefn cast(node: SyntaxNode) -> Option<Self>
fn cast(node: SyntaxNode) -> Option<Self>
Attempt to cast a SyntaxNode into this AST type.
Returns Some(Self) if the node’s kind matches, None otherwise.
Sourcefn syntax(&self) -> &SyntaxNode
fn syntax(&self) -> &SyntaxNode
Return a reference to the underlying SyntaxNode.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".