pub trait AstNode: Debug + Sized {
// Required methods
fn ancestors(&self) -> impl Iterator<Item = Self>;
fn children(&self) -> impl Iterator<Item = Self>;
fn parent(&self) -> Option<Self>;
fn next_named_node(&self) -> Option<Self>;
fn previous_named_node(&self) -> Option<Self>;
fn next_sibling(&self) -> Option<Self>;
fn previous_sibling(&self) -> Option<Self>;
fn text(&self) -> GritResult<Cow<'_, str>>;
fn byte_range(&self) -> ByteRange;
fn code_range(&self) -> CodeRange;
fn walk(&self) -> impl AstCursor<Node = Self>;
}Expand description
Represents an AST node and offers convenient AST-specific functionality.
This trait should be free from dependencies on TreeSitter. This also implies it should not expose details about the node that may make it infeasible to implement the trait by implementations that use different node representations internally.
Required Methods§
Sourcefn ancestors(&self) -> impl Iterator<Item = Self>
fn ancestors(&self) -> impl Iterator<Item = Self>
Returns an iterator over the node’s ancestors, starting with the node itself and moving up to the root.
Sourcefn parent(&self) -> Option<Self>
fn parent(&self) -> Option<Self>
Returns the node’s parent.
Returns None if this is the root node.
Sourcefn next_named_node(&self) -> Option<Self>
fn next_named_node(&self) -> Option<Self>
Returns the next node in the tree, ignoring trivia such as whitespace.
Sourcefn previous_named_node(&self) -> Option<Self>
fn previous_named_node(&self) -> Option<Self>
Returns the previous node in the tree, ignoring trivia such as whitespace.
Sourcefn next_sibling(&self) -> Option<Self>
fn next_sibling(&self) -> Option<Self>
Returns the next adjacent node.
Sourcefn previous_sibling(&self) -> Option<Self>
fn previous_sibling(&self) -> Option<Self>
Returns the previous adjacent node.
Sourcefn text(&self) -> GritResult<Cow<'_, str>>
fn text(&self) -> GritResult<Cow<'_, str>>
Returns the text representation of the node.
Sourcefn byte_range(&self) -> ByteRange
fn byte_range(&self) -> ByteRange
Returns the byte range of the node.
Sourcefn code_range(&self) -> CodeRange
fn code_range(&self) -> CodeRange
Returns the code range 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.