pub trait AstNode<N: TreeNode>: Sized {
Show 16 methods
// Required methods
fn can_cast(kind: SyntaxKind) -> bool;
fn cast(inner: N) -> Option<Self>;
fn inner(&self) -> &N;
// Provided methods
fn kind(&self) -> SyntaxKind { ... }
fn text<'a>(&'a self) -> impl Display
where N: 'a { ... }
fn span(&self) -> Span { ... }
fn token<C>(&self) -> Option<C>
where C: AstToken<N::Token> { ... }
fn tokens<'a, C>(&'a self) -> impl Iterator<Item = C>
where C: AstToken<N::Token>,
N: 'a { ... }
fn last_token<C>(&self) -> Option<C>
where C: AstToken<N::Token> { ... }
fn child<C>(&self) -> Option<C>
where C: AstNode<N> { ... }
fn children<'a, C>(&'a self) -> impl Iterator<Item = C>
where C: AstNode<N>,
N: 'a { ... }
fn parent<'a, P>(&self) -> Option<P>
where P: AstNode<N>,
N: 'a { ... }
fn scope_span<O, C>(&self) -> Option<Span>
where O: AstToken<N::Token>,
C: AstToken<N::Token> { ... }
fn braced_scope_span(&self) -> Option<Span> { ... }
fn heredoc_scope_span(&self) -> Option<Span> { ... }
fn descendants<'a, D>(&'a self) -> impl Iterator<Item = D>
where D: AstNode<N>,
N: 'a { ... }
}Expand description
A trait implemented by AST nodes.
Required Methods§
Sourcefn can_cast(kind: SyntaxKind) -> bool
fn can_cast(kind: SyntaxKind) -> bool
Determines if the kind can be cast to this representation.
Provided Methods§
Sourcefn kind(&self) -> SyntaxKind
fn kind(&self) -> SyntaxKind
Gets the syntax kind of the node.
Sourcefn text<'a>(&'a self) -> impl Displaywhere
N: 'a,
fn text<'a>(&'a self) -> impl Displaywhere
N: 'a,
Gets the text of the node.
As node text is not contiguous, this returns a type that implements
Display.
Sourcefn tokens<'a, C>(&'a self) -> impl Iterator<Item = C>
fn tokens<'a, C>(&'a self) -> impl Iterator<Item = C>
Gets all the token children that can cast to an expected type.
Sourcefn last_token<C>(&self) -> Option<C>
fn last_token<C>(&self) -> Option<C>
Gets the last token of the node and attempts to cast it to an expected type.
Returns None if there is no last token or if it cannot be casted to
the expected type.
Sourcefn child<C>(&self) -> Option<C>where
C: AstNode<N>,
fn child<C>(&self) -> Option<C>where
C: AstNode<N>,
Gets the first node child that can cast to an expected type.
Sourcefn children<'a, C>(&'a self) -> impl Iterator<Item = C>where
C: AstNode<N>,
N: 'a,
fn children<'a, C>(&'a self) -> impl Iterator<Item = C>where
C: AstNode<N>,
N: 'a,
Gets all node children that can cast to an expected type.
Sourcefn parent<'a, P>(&self) -> Option<P>where
P: AstNode<N>,
N: 'a,
fn parent<'a, P>(&self) -> Option<P>where
P: AstNode<N>,
N: 'a,
Gets the parent of the node if the underlying tree node has a parent.
Returns None if the node has no parent or if the parent node is not of
the expected type.
Sourcefn scope_span<O, C>(&self) -> Option<Span>
fn scope_span<O, C>(&self) -> Option<Span>
Calculates the span of a scope given the node where the scope is visible.
Returns None if the node does not contain the open and close tokens as
children.
Sourcefn braced_scope_span(&self) -> Option<Span>
fn braced_scope_span(&self) -> Option<Span>
Gets the interior span of child opening and closing brace tokens for the node.
The span starts from immediately after the opening brace token and ends immediately before the closing brace token.
Returns None if the node does not contain child brace tokens.
Sourcefn heredoc_scope_span(&self) -> Option<Span>
fn heredoc_scope_span(&self) -> Option<Span>
Gets the interior span of child opening and closing heredoc tokens for the node.
The span starts from immediately after the opening heredoc token and ends immediately before the closing heredoc token.
Returns None if the node does not contain child heredoc tokens.
Sourcefn descendants<'a, D>(&'a self) -> impl Iterator<Item = D>where
D: AstNode<N>,
N: 'a,
fn descendants<'a, D>(&'a self) -> impl Iterator<Item = D>where
D: AstNode<N>,
N: 'a,
Gets the node descendants (including self) from this node that can be cast to the expected type.
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.