TreeNode

Trait TreeNode 

Source
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§

Source

type Token: TreeToken

The associated token type for the tree node.

Required Methods§

Source

fn parent(&self) -> Option<Self>

Gets the parent node of the node.

Returns None if the node is a root.

Source

fn kind(&self) -> SyntaxKind

Gets the syntax kind of the node.

Source

fn text(&self) -> impl Display

Gets the text of the node.

Node text is not contiguous, so the returned value implements Display.

Source

fn span(&self) -> Span

Gets the span of the node.

Source

fn children(&self) -> impl Iterator<Item = Self>

Gets the children nodes of the node.

Source

fn children_with_tokens( &self, ) -> impl Iterator<Item = NodeOrToken<Self, Self::Token>>

Gets all the children of the node, including tokens.

Source

fn last_token(&self) -> Option<Self::Token>

Gets the last token of the node.

Source

fn descendants(&self) -> impl Iterator<Item = Self>

Gets the node descendants of the node.

Source

fn ancestors(&self) -> impl Iterator<Item = Self>

Gets the ancestors 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.

Implementors§