Skip to main content

MethodQuery

Struct MethodQuery 

Source
pub struct MethodQuery<'a> { /* private fields */ }
Expand description

A chainable builder for method queries.

Construct with MethodQuery::new, optionally set deps and filter, then call run or run_with_definitions to execute.

§Example

use rust_meth_lib::query::MethodQuery;
use rust_meth_lib::analyzer::find_rust_analyzer;

let ra_path = find_rust_analyzer().unwrap();

let methods = MethodQuery::new("String")
    .filter("push")
    .run(&ra_path)
    .unwrap();

for m in methods {
    println!("{}", m.name);
}

Implementations§

Source§

impl<'a> MethodQuery<'a>

Source

pub const fn new(type_name: &'a str) -> Self

Creates a new query for the given Rust type expression.

§Example
use rust_meth_lib::query::MethodQuery;
let q = MethodQuery::new("Vec<u8>");
Source

pub const fn deps(self, deps: &'a str) -> Self

Sets the TOML dependency string for third-party crate types.

Accepts the same format as query_methods, a raw TOML snippet that would appear under [dependencies]. Multiple crates are newline-separated.

§Example
use rust_meth_lib::query::MethodQuery;
use rust_meth_lib::analyzer::find_rust_analyzer;

let ra_path = find_rust_analyzer().unwrap();
let methods = MethodQuery::new("serde_json::Value")
    .deps(r#"serde_json = "1.0""#)
    .run(&ra_path)
    .unwrap();
Source

pub const fn filter(self, query: &'a str) -> Self

Applies a filter to the results after the query completes.

Uses the same scoring as filter_methods: exact > prefix > substring. Methods that don’t match are excluded from results.

§Example
use rust_meth_lib::query::MethodQuery;
use rust_meth_lib::analyzer::find_rust_analyzer;

let ra_path = find_rust_analyzer().unwrap();
let methods = MethodQuery::new("HashMap<String, u32>")
    .filter("get")
    .run(&ra_path)
    .unwrap();
Source

pub fn run(self, ra_path: &Path) -> Result<Vec<Method>>

Executes the query and returns matching methods.

Runs query_methods then applies the filter if one was set. Returns owned Method values.

§Errors

Propagates any error from the underlying LSP session.

Source

pub fn run_with_definitions(self, ra_path: &Path) -> Result<Vec<MethodResult>>

Executes the query, applies the filter, and resolves source locations for each matching method sequentially.

Methods where rust-analyzer has no source location are included with definition: None rather than being silently dropped.

Note: For third-party crate types, each definition query requires Cargo to resolve dependencies inside an ephemeral probe project. With many matching methods this can be slow. Use a tight filter to limit the number of definition queries, or prefer stdlib types where Cargo resolution is not required.

§Errors

Propagates any fatal LSP error. Per-method Ok(None) definition results are not errors.

Source

pub const fn limit(self, limit: usize) -> Self

Limits the maximum number of methods returned after filtering.

Useful for keeping definition resolution fast when a broad filter matches many items.

Auto Trait Implementations§

§

impl<'a> Freeze for MethodQuery<'a>

§

impl<'a> RefUnwindSafe for MethodQuery<'a>

§

impl<'a> Send for MethodQuery<'a>

§

impl<'a> Sync for MethodQuery<'a>

§

impl<'a> Unpin for MethodQuery<'a>

§

impl<'a> UnsafeUnpin for MethodQuery<'a>

§

impl<'a> UnwindSafe for MethodQuery<'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> 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.