pub trait Node<'tree>:
Debug
+ Clone
+ Copy
+ PartialEq
+ Eq
+ Hash {
type WithLifetime<'a>: Node<'a>;
const KIND: &'static str;
Show 27 methods
// Required methods
fn try_from_raw(node: Node<'tree>) -> NodeResult<'tree, Self>;
fn raw(&self) -> &Node<'tree>;
fn raw_mut(&mut self) -> &mut Node<'tree>;
fn into_raw(self) -> Node<'tree>;
// Provided methods
unsafe fn from_raw_unchecked(node: Node<'tree>) -> Self { ... }
fn upcast(self) -> UntypedNode<'tree> { ... }
fn utf8_text<'a>(&self, source: &'a [u8]) -> Result<&'a str, Utf8Error> { ... }
fn utf16_text<'a>(&self, source: &'a [u16]) -> &'a [u16] { ... }
fn prefixes(&self) -> impl Iterator<Item = UntypedNode<'tree>> { ... }
fn suffixes(&self) -> impl Iterator<Item = UntypedNode<'tree>> { ... }
fn walk(&self) -> TreeCursor<'tree> { ... }
fn parent(&self) -> Option<UntypedNode<'tree>> { ... }
fn next_named_sibling(&self) -> Option<UntypedNode<'tree>> { ... }
fn prev_named_sibling(&self) -> Option<UntypedNode<'tree>> { ... }
fn named_child_count(&self) -> usize { ... }
fn to_sexp(&self) -> String { ... }
fn kind(&self) -> &'static str { ... }
fn is_named(&self) -> bool { ... }
fn has_changes(&self) -> bool { ... }
fn has_error(&self) -> bool { ... }
fn start_byte(&self) -> usize { ... }
fn end_byte(&self) -> usize { ... }
fn start_position(&self) -> Point { ... }
fn end_position(&self) -> Point { ... }
fn range(&self) -> Range { ... }
fn byte_range(&self) -> Range<usize> { ... }
fn edit(&mut self, edit: &InputEdit) { ... }
}Expand description
Typed node wrapper.
This implements TryFrom<tree_sitter::Node<'tree>>, which will succeed iff the node is of the correct type.
That is how you convert untyped nodes into types nodes. If you’re absolutely sure the node is
correct, you may also use Node::from_raw_unchecked, though it’s honestly probably not
worth the possible performance gain.
You can get extra nodes (e.g. comments) that are before and after this node with prefixes and suffixes.
Required Associated Constants§
Sourceconst KIND: &'static str
const KIND: &'static str
Kind of nodes this wraps.
For nodes that map directly to tree-sitter nodes, this is the tree-sitter node’s name. For
nodes like unions, UntypedNode, or NodeResults, which don’t have a simple kind
(especially static), this is {...}.
Required Associated Types§
Sourcetype WithLifetime<'a>: Node<'a>
type WithLifetime<'a>: Node<'a>
The same type, but with a different lifetime.
Required Methods§
Sourcefn try_from_raw(node: Node<'tree>) -> NodeResult<'tree, Self>
fn try_from_raw(node: Node<'tree>) -> NodeResult<'tree, Self>
Check that the tree-sitter node is the correct kind, and if it is, wrap.
Returns Err if the node is not of the correct kind.
Sourcefn raw(&self) -> &Node<'tree>
fn raw(&self) -> &Node<'tree>
The wrapped tree-sitter node.
Note that most methods you should call on this struct directly.
Provided Methods§
Sourceunsafe fn from_raw_unchecked(node: Node<'tree>) -> Self
unsafe fn from_raw_unchecked(node: Node<'tree>) -> Self
Assume that tree-sitter node is the correct kind and wrap.
§Safety
The node must be of the correct kind.
Sourcefn upcast(self) -> UntypedNode<'tree>
fn upcast(self) -> UntypedNode<'tree>
Upcast into an untyped node.
The inverse is UntypedNode::downcast.
Sourcefn utf16_text<'a>(&self, source: &'a [u16]) -> &'a [u16]
fn utf16_text<'a>(&self, source: &'a [u16]) -> &'a [u16]
Sourcefn prefixes(&self) -> impl Iterator<Item = UntypedNode<'tree>>
fn prefixes(&self) -> impl Iterator<Item = UntypedNode<'tree>>
Returns any extra nodes before this one, e.g., comments.
Nodes are iterated first to last (by source location).
Sourcefn suffixes(&self) -> impl Iterator<Item = UntypedNode<'tree>>
fn suffixes(&self) -> impl Iterator<Item = UntypedNode<'tree>>
Returns any extra nodes after this one, e.g., comments.
Nodes are iterated first to last (by source location).
Sourcefn walk(&self) -> TreeCursor<'tree>
fn walk(&self) -> TreeCursor<'tree>
Get a cursor for this node
Sourcefn parent(&self) -> Option<UntypedNode<'tree>>
fn parent(&self) -> Option<UntypedNode<'tree>>
Get the node’s immediate parent
Sourcefn next_named_sibling(&self) -> Option<UntypedNode<'tree>>
fn next_named_sibling(&self) -> Option<UntypedNode<'tree>>
Get the node’s immediate named next sibling
Sourcefn prev_named_sibling(&self) -> Option<UntypedNode<'tree>>
fn prev_named_sibling(&self) -> Option<UntypedNode<'tree>>
Get the node’s immediate named previous sibling
Sourcefn named_child_count(&self) -> usize
fn named_child_count(&self) -> usize
Get the number of named children
Sourcefn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Get this node’s tree-sitter name. See tree-sitter’s Node::kind
Sourcefn is_named(&self) -> bool
fn is_named(&self) -> bool
Check if this node is named. See tree-sitter’s Node::is_named
Sourcefn has_changes(&self) -> bool
fn has_changes(&self) -> bool
Check if this node has been edited
Sourcefn has_error(&self) -> bool
fn has_error(&self) -> bool
Check if this node represents a syntax error or contains any syntax errors anywhere within it
Sourcefn start_byte(&self) -> usize
fn start_byte(&self) -> usize
Get the byte offset where this node starts
Sourcefn start_position(&self) -> Point
fn start_position(&self) -> Point
Get the row and column where this node starts
Sourcefn end_position(&self) -> Point
fn end_position(&self) -> Point
Get the row and column where this node ends
Sourcefn range(&self) -> Range
fn range(&self) -> Range
Get the byte range and row and column range where this node is located
Sourcefn byte_range(&self) -> Range<usize>
fn byte_range(&self) -> Range<usize>
Get the byte range where this node is located
Sourcefn edit(&mut self, edit: &InputEdit)
fn edit(&mut self, edit: &InputEdit)
Edit this node to keep it in-sync with source code that has been edited. See
tree-sitter’s Node::edit
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.