Skip to main content

Query

Struct Query 

Source
pub struct Query<Q> {
    pub raw: Q,
    pub capture_names: Vec<String>,
    pub patterns: Vec<Pattern>,
    pub metadata: Vec<Metadata>,
}
Expand description

A compiled query and its metadata in the shared format.

Fields§

§raw: Q

Runtime-specific compiled query.

§capture_names: Vec<String>

Capture names indexed by crate::backend::Capture::index.

§patterns: Vec<Pattern>

Pattern metadata indexed by Match::pattern.

§metadata: Vec<Metadata>

Metadata required for each capture across all query patterns.

Implementations§

Source§

impl<Q> Query<Q>

Source

pub fn new(raw: Q, capture_names: Vec<String>, patterns: Vec<Pattern>) -> Self

Store a compiled query and determine the node metadata each capture needs.

Source

pub fn matches<B: Backend<Query = Q>>( &self, backend: &mut B, tree: &B::Tree, source: &str, ) -> Result<Vec<Match>, Error>

Run a query and filter its matches. Empty queries skip runtime execution.

§Errors

Returns runtime, predicate, or invalid-range errors.

Source

pub fn filtered( &self, matches: Vec<Match>, source: &str, ) -> Result<Vec<Match>, Error>

Validate captures, filter custom predicates, and apply capture offsets.

Reuses the input vector and preserves the order of accepted matches. Input indices must refer to this query.

§Errors

Returns Error::InvalidRange for invalid source boundaries or offsets.

§Panics

Panics if a match references a pattern outside Self::patterns.

Auto Trait Implementations§

§

impl<Q> Forget for Query<Q>

§

impl<Q> Freeze for Query<Q>
where Q: Freeze,

§

impl<Q> Move for Query<Q>

§

impl<Q> RefUnwindSafe for Query<Q>
where Q: RefUnwindSafe,

§

impl<Q> Send for Query<Q>
where Q: Send,

§

impl<Q> Sync for Query<Q>
where Q: Sync,

§

impl<Q> Unpin for Query<Q>
where Q: Unpin,

§

impl<Q> UnsafeUnpin for Query<Q>
where Q: UnsafeUnpin,

§

impl<Q> UnwindSafe for Query<Q>
where Q: UnwindSafe,

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 = !

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.