Skip to main content

Node

Struct Node 

Source
pub struct Node { /* private fields */ }
Expand description

A single syntax node within a Tree.

Nodes hold a strong reference to their parent tree so they remain valid regardless of how the tree is moved or stored at the FFI boundary.

Implementations§

Source§

impl Node

Source

pub fn kind(&self) -> String

Return the node’s kind name (e.g. "function_definition").

Source

pub fn kind_id(&self) -> u16

Return the node’s numeric kind ID.

Source

pub fn start_byte(&self) -> usize

Return the inclusive start byte offset of this node.

Source

pub fn end_byte(&self) -> usize

Return the exclusive end byte offset of this node.

Source

pub fn byte_range(&self) -> ByteRange

Return the node’s byte range as a ByteRange.

Callers should slice their own source bytes — this is a zero-copy text accessor.

Source

pub fn start_position(&self) -> Point

Return the start Point (row, column).

Source

pub fn end_position(&self) -> Point

Return the end Point (row, column).

Source

pub fn is_named(&self) -> bool

True when this node is named (not punctuation/whitespace).

Source

pub fn is_error(&self) -> bool

True when this is an error node.

Source

pub fn is_missing(&self) -> bool

True when this is a missing-token node.

Source

pub fn is_extra(&self) -> bool

True when this is an “extra” node (e.g. a comment).

Source

pub fn has_error(&self) -> bool

True when this node or any descendant is an error.

Source

pub fn parent(&self) -> Option<Node>

Return this node’s parent, if any.

Source

pub fn child(&self, index: u32) -> Option<Node>

Return the i-th child of this node, if any.

Source

pub fn child_count(&self) -> usize

Total number of children (including unnamed).

Source

pub fn named_child(&self, index: u32) -> Option<Node>

Return the i-th named child of this node, if any.

Source

pub fn named_child_count(&self) -> usize

Number of named children of this node.

Source

pub fn child_by_field_name(&self, name: &str) -> Option<Node>

Look up a child by its grammar-defined field name.

Source

pub fn to_sexp(&self) -> String

Return the S-expression form of this node’s subtree.

Source

pub fn walk(&self) -> TreeCursor

Return a TreeCursor positioned at this node.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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> 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.