Struct tree_sitter::TreeCursor

source ·
pub struct TreeCursor<'cursor>(/* private fields */);
Expand description

A stateful object for walking a syntax Tree efficiently.

Implementations§

source§

impl<'a> TreeCursor<'a>

source

pub const unsafe fn from_raw(raw: TSTreeCursor) -> TreeCursor<'a>

Reconstructs a TreeCursor from a raw pointer.

§Safety

ptr must be non-null.

source

pub fn into_raw(self) -> TSTreeCursor

Consumes the TreeCursor, returning a raw pointer to the underlying C structure.

source§

impl<'cursor> TreeCursor<'cursor>

source

pub fn node(&self) -> Node<'cursor>

Get the tree cursor’s current Node.

source

pub fn field_id(&self) -> Option<NonZeroU16>

Get the numerical field id of this tree cursor’s current node.

See also field_name.

source

pub fn field_name(&self) -> Option<&'static str>

Get the field name of this tree cursor’s current node.

source

pub fn depth(&self) -> u32

Get the numerical field id of this tree cursor’s current node.

See also field_name.

source

pub fn descendant_index(&self) -> usize

Get the index of the cursor’s current node out of all of the descendants of the original node that the cursor was constructed with

source

pub fn goto_first_child(&mut self) -> bool

Move this cursor to the first child of its current node.

This returns true if the cursor successfully moved, and returns false if there were no children.

source

pub fn goto_last_child(&mut self) -> bool

Move this cursor to the last child of its current node.

This returns true if the cursor successfully moved, and returns false if there were no children.

Note that this function may be slower than goto_first_child because it needs to iterate through all the children to compute the child’s position.

source

pub fn goto_parent(&mut self) -> bool

Move this cursor to the parent of its current node.

This returns true if the cursor successfully moved, and returns false if there was no parent node (the cursor was already on the root node).

source

pub fn goto_next_sibling(&mut self) -> bool

Move this cursor to the next sibling of its current node.

This returns true if the cursor successfully moved, and returns false if there was no next sibling node.

source

pub fn goto_descendant(&mut self, descendant_index: usize)

Move the cursor to the node that is the nth descendant of the original node that the cursor was constructed with, where zero represents the original node itself.

source

pub fn goto_previous_sibling(&mut self) -> bool

Move this cursor to the previous sibling of its current node.

This returns true if the cursor successfully moved, and returns false if there was no previous sibling node.

Note, that this function may be slower than goto_next_sibling due to how node positions are stored. In the worst case, this will need to iterate through all the children upto the previous sibling node to recalculate its position.

source

pub fn goto_first_child_for_byte(&mut self, index: usize) -> Option<usize>

Move this cursor to the first child of its current node that extends beyond the given byte offset.

This returns the index of the child node if one was found, and returns None if no such child was found.

source

pub fn goto_first_child_for_point(&mut self, point: Point) -> Option<usize>

Move this cursor to the first child of its current node that extends beyond the given byte offset.

This returns the index of the child node if one was found, and returns None if no such child was found.

source

pub fn reset(&mut self, node: Node<'cursor>)

Re-initialize this tree cursor to start at a different node.

source

pub fn reset_to(&mut self, cursor: &TreeCursor<'cursor>)

Re-initialize a tree cursor to the same position as another cursor.

Unlike reset, this will not lose parent information and allows reusing already created cursors.

Trait Implementations§

source§

impl Clone for TreeCursor<'_>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Drop for TreeCursor<'_>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for TreeCursor<'_>

source§

impl Sync for TreeCursor<'_>

Auto Trait Implementations§

§

impl<'cursor> RefUnwindSafe for TreeCursor<'cursor>

§

impl<'cursor> Unpin for TreeCursor<'cursor>

§

impl<'cursor> UnwindSafe for TreeCursor<'cursor>

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> 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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.