Skip to main content

Node

Struct Node 

Source
pub struct Node<'a>(/* private fields */);
Expand description

An AST node.

The inner tree_sitter::Node is reached through Node::as_tree_sitter for advanced use cases that need direct access to the underlying tree-sitter API; the field itself is private so a tree-sitter version bump cannot silently reshape this struct’s public layout.

Implementations§

Source§

impl<'a> Node<'a>

Source

pub fn as_tree_sitter(&self) -> OtherNode<'a>

Returns the underlying tree_sitter::Node for callers that want to drive their own traversal alongside the metric walker.

tree_sitter::Node is Copy, so the node is returned by value. The returned node borrows the same source-tree lifetime as self.

The tree-sitter re-export this exposes is value-not-stable: the underlying pin may bump in any minor release, so node shape and node-kind ids are not part of this crate’s stability contract (see the tree_sitter re-export note in the crate root).

Source

pub fn has_error(&self) -> bool

Checks if a node represents a syntax error or contains any syntax errors anywhere within it.

Source

pub fn preorder(&self) -> Preorder<'a>

Returns a pre-order iterator over this node and all of its descendants (this node first, then each child subtree left to right).

The traversal is allocation-light: it reuses one work stack and visits each node exactly once, so a full walk is O(n) in the subtree size. Every yielded Node carries the underlying tree lifetime 'a, so callers may collect or retain the handles.

This is the Rust counterpart of the Python Node.walk() binding (issue #728): the binding wraps each yielded node, so Rust and Python share one traversal order.

Source

pub fn descendants_by_kind(&self, kinds: &[&str]) -> Vec<Node<'a>>

Collects every node in this subtree (this node included) whose kind is listed in kinds, in pre-order.

Membership is an exact match against the raw grammar kind — the same unaltered vocabulary crate::Ast::root_node exposes, not the Alterator-curated kinds crate::Ast::dump emits. This is the Rust counterpart of the Python Node.descendants_by_kind() binding (issue #728).

Trait Implementations§

Source§

impl<'a> Clone for Node<'a>

Source§

fn clone(&self) -> Node<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Node<'a>

Source§

impl<'a> Debug for Node<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Node<'a>

§

impl<'a> RefUnwindSafe for Node<'a>

§

impl<'a> Send for Node<'a>

§

impl<'a> Sync for Node<'a>

§

impl<'a> Unpin for Node<'a>

§

impl<'a> UnsafeUnpin for Node<'a>

§

impl<'a> UnwindSafe for Node<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.