QuickMatch

Struct QuickMatch 

Source
pub struct QuickMatch<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> QuickMatch<'a>

Source

pub fn new(items: &[&'a str]) -> Self

Expect the items to be pre-formatted (lowercase)

Examples found in repository?
examples/autocomplete.rs (line 30)
5fn main() {
6    let products = vec![
7        "Apple iPhone 15 Pro",
8        "Apple MacBook Pro 16",
9        "Apple AirPods Pro",
10        "Samsung Galaxy S24",
11        "Samsung Galaxy Tab",
12        "Sony PlayStation 5",
13        "Sony WH-1000XM5 Headphones",
14        "Microsoft Surface Pro",
15        "Microsoft Xbox Series X",
16        "Dell XPS 13 Laptop",
17        "Dell UltraSharp Monitor",
18        "Logitech MX Master Mouse",
19        "Logitech Mechanical Keyboard",
20        "Canon EOS R5 Camera",
21        "Nikon Z9 Camera",
22        "GoPro Hero 12",
23    ]
24    .into_iter()
25    .map(|s| s.to_lowercase())
26    .collect::<Vec<_>>();
27
28    let products_ref = products.iter().map(|s| s.as_str()).collect::<Vec<_>>();
29
30    let matcher = QuickMatch::new(&products_ref);
31
32    println!("Type to search (press Ctrl+C to exit):");
33    println!("Try: 'apple', 'pro', 'laptop', 'headphones', etc.\n");
34
35    loop {
36        print!("> ");
37        io::stdout().flush().unwrap();
38
39        let mut input = String::new();
40        io::stdin().read_line(&mut input).unwrap();
41        let query = input.trim();
42
43        if query.is_empty() {
44            continue;
45        }
46
47        let results = matcher.matches(query);
48
49        if results.is_empty() {
50            println!("  No matches found\n");
51        } else {
52            println!("  {} result(s):", results.len());
53            for result in results {
54                println!("    • {}", result);
55            }
56            println!();
57        }
58    }
59}
Source

pub fn new_with(items: &[&'a str], config: QuickMatchConfig) -> Self

Expect the items to be pre-formatted (lowercase)

Source

pub fn matches(&self, query: &str) -> Vec<&'a str>

limit: max number of returned matches

max_trigrams: max number of processed trigrams in unknown words (0-10 recommended)

Examples found in repository?
examples/autocomplete.rs (line 47)
5fn main() {
6    let products = vec![
7        "Apple iPhone 15 Pro",
8        "Apple MacBook Pro 16",
9        "Apple AirPods Pro",
10        "Samsung Galaxy S24",
11        "Samsung Galaxy Tab",
12        "Sony PlayStation 5",
13        "Sony WH-1000XM5 Headphones",
14        "Microsoft Surface Pro",
15        "Microsoft Xbox Series X",
16        "Dell XPS 13 Laptop",
17        "Dell UltraSharp Monitor",
18        "Logitech MX Master Mouse",
19        "Logitech Mechanical Keyboard",
20        "Canon EOS R5 Camera",
21        "Nikon Z9 Camera",
22        "GoPro Hero 12",
23    ]
24    .into_iter()
25    .map(|s| s.to_lowercase())
26    .collect::<Vec<_>>();
27
28    let products_ref = products.iter().map(|s| s.as_str()).collect::<Vec<_>>();
29
30    let matcher = QuickMatch::new(&products_ref);
31
32    println!("Type to search (press Ctrl+C to exit):");
33    println!("Try: 'apple', 'pro', 'laptop', 'headphones', etc.\n");
34
35    loop {
36        print!("> ");
37        io::stdout().flush().unwrap();
38
39        let mut input = String::new();
40        io::stdin().read_line(&mut input).unwrap();
41        let query = input.trim();
42
43        if query.is_empty() {
44            continue;
45        }
46
47        let results = matcher.matches(query);
48
49        if results.is_empty() {
50            println!("  No matches found\n");
51        } else {
52            println!("  {} result(s):", results.len());
53            for result in results {
54                println!("    • {}", result);
55            }
56            println!();
57        }
58    }
59}
Source

pub fn matches_with( &self, query: &str, config: &QuickMatchConfig, ) -> Vec<&'a str>

limit: max number of returned matches

max_trigrams: max number of processed trigrams in unknown words (0-10 recommended)

Trait Implementations§

Source§

impl<'a> Send for QuickMatch<'a>

Source§

impl<'a> Sync for QuickMatch<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for QuickMatch<'a>

§

impl<'a> RefUnwindSafe for QuickMatch<'a>

§

impl<'a> Unpin for QuickMatch<'a>

§

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