pub trait TreeNode:
Clone
+ Debug
+ PartialEq
+ Eq
+ Hash {
type Token: TreeToken;
// Required methods
fn parent(&self) -> Option<Self>;
fn kind(&self) -> SyntaxKind;
fn text(&self) -> impl Display;
fn span(&self) -> Span;
fn children(&self) -> impl Iterator<Item = Self>;
fn children_with_tokens(
&self,
) -> impl Iterator<Item = NodeOrToken<Self, Self::Token>>;
fn last_token(&self) -> Option<Self::Token>;
fn descendants(&self) -> impl Iterator<Item = Self>;
fn ancestors(&self) -> impl Iterator<Item = Self>;
}Expand description
A trait that abstracts the underlying representation of a syntax tree node.
The default node type is SyntaxNode for all AST nodes.
Required Associated Types§
Required Methods§
Sourcefn parent(&self) -> Option<Self>
fn parent(&self) -> Option<Self>
Gets the parent node of the node.
Returns None if the node is a root.
Sourcefn kind(&self) -> SyntaxKind
fn kind(&self) -> SyntaxKind
Gets the syntax kind of the node.
Sourcefn text(&self) -> impl Display
fn text(&self) -> impl Display
Gets the text of the node.
Node text is not contiguous, so the returned value implements Display.
Sourcefn children_with_tokens(
&self,
) -> impl Iterator<Item = NodeOrToken<Self, Self::Token>>
fn children_with_tokens( &self, ) -> impl Iterator<Item = NodeOrToken<Self, Self::Token>>
Gets all the children of the node, including tokens.
Sourcefn last_token(&self) -> Option<Self::Token>
fn last_token(&self) -> Option<Self::Token>
Gets the last token of the node.
Sourcefn descendants(&self) -> impl Iterator<Item = Self>
fn descendants(&self) -> impl Iterator<Item = Self>
Gets the node descendants of the node.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.