Skip to main content

Cursor

Struct Cursor 

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

An AST cursor.

Implementations§

Source§

impl<'a> Cursor<'a>

Source

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

Re-seats the cursor on node.

Source

pub fn goto_next_sibling(&mut self) -> bool

Moves to the next sibling; false when there is none.

Source

pub fn goto_first_child(&mut self) -> bool

Moves to the first child; false when there is none.

Source

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

Moves to the first child that ends after byte and returns its index in Node::children order, or None when no child does.

“Ends after” is strict, so a zero-width child at byte — a MISSING token the parser inserted during error recovery — is skipped and the cursor lands on its successor. That is the one way this differs from children().position(..), which finds such a node; a caller resolving a node’s own index must therefore check Cursor::node against it, as both call sites here do.

The index is what makes this worth having over a sibling scan: tree-sitter stores a repeat() child list under balanced hidden nodes and skips each by its cached visible-child count, so this is O(log n) in the sibling count where children().position(..) is O(n) — the difference between a linear and a quadratic walk when every child of a wide list asks for its own index.

Source

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

The node the cursor currently sits on.

Trait Implementations§

Source§

impl<'a> Clone for Cursor<'a>

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<'a> Freeze for Cursor<'a>

§

impl<'a> RefUnwindSafe for Cursor<'a>

§

impl<'a> Send for Cursor<'a>

§

impl<'a> Sync for Cursor<'a>

§

impl<'a> Unpin for Cursor<'a>

§

impl<'a> UnsafeUnpin for Cursor<'a>

§

impl<'a> UnwindSafe for Cursor<'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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.