Skip to main content

QueryMatch

Struct QueryMatch 

Source
pub struct QueryMatch<'query, 'tree> { /* private fields */ }
Expand description

Wrapper around tree_sitter::QueryMatch

Implementations§

Source§

impl<'query, 'tree> QueryMatch<'query, 'tree>

Source

pub unsafe fn new( query_match: &QueryMatch<'query, 'tree>, query: &'query Query, tree: &'tree Tree, ) -> Self

Wrap a tree-sitter query match.

§Safety

The query match must be from the given tree and query. Additionally, query_match’s lifetime must be longer than the “lifetime” where any methods may be called on this structure, despite not being captured in the signature (the structure can outlive query_match because it stores a raw pointer, but most of its methods dereference, so when query_match is no longer live they cause UB).

Source

pub fn query(&self) -> &'query Query

Get the query that the match is from

Source

pub fn tree(&self) -> &'tree Tree

Get the tree that the match is from

Source

pub fn iter_captures(&self) -> impl Iterator<Item = QueryCapture<'query, 'tree>>

Iterate all captures in the order they appear.

Source

pub fn capture(&self, index: usize) -> Option<QueryCapture<'query, 'tree>>

Get the capture at the given index (order it appears).

Source

pub fn capture_named(&self, name: &str) -> Option<QueryCapture<'query, 'tree>>

Get the first occurrence of the capture with the given name.

Source

pub fn captures_named<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = QueryCapture<'query, 'tree>> + 'a

Get every occurrence of the captures with the given name.

Source

pub fn capture_count(&self) -> usize

Get the number of captures in this match.

Source

pub fn pattern_index(&self) -> usize

Get the pattern index of this match.

Source

pub fn id(&self) -> u32

Get the id of this match (honestly I don’t know what this does because it’s not documented)

Source

pub fn remove(&self)

Remove the match (honestly I don’t know what this does because it’s not documented)

Source

pub fn nodes_for_capture_index( &self, capture_index: u32, ) -> impl Iterator<Item = Node<'tree>> + '_

Get the nodes that were captures by the capture at the given index.

Source

pub fn as_inner(&self) -> &QueryMatch<'query, 'tree>

Get the underlying tree_sitter::QueryMatch

Source

pub fn into_inner( self, ) -> (*const QueryMatch<'query, 'tree>, &'query Query, &'tree Tree)

Destruct into the underlying tree_sitter::QueryMatch raw pointer, as well as the query and tree

Trait Implementations§

Source§

impl<'query, 'tree> Debug for QueryMatch<'query, 'tree>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'query, 'tree> !Send for QueryMatch<'query, 'tree>

§

impl<'query, 'tree> !Sync for QueryMatch<'query, 'tree>

§

impl<'query, 'tree> Freeze for QueryMatch<'query, 'tree>

§

impl<'query, 'tree> RefUnwindSafe for QueryMatch<'query, 'tree>

§

impl<'query, 'tree> Unpin for QueryMatch<'query, 'tree>

§

impl<'query, 'tree> UnsafeUnpin for QueryMatch<'query, 'tree>

§

impl<'query, 'tree> UnwindSafe for QueryMatch<'query, 'tree>

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