pub struct QuickMatch<'a> { /* private fields */ }Implementations§
Source§impl<'a> QuickMatch<'a>
impl<'a> QuickMatch<'a>
Sourcepub fn new(items: &[&'a str]) -> Self
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}Sourcepub fn new_with(items: &[&'a str], config: QuickMatchConfig) -> Self
pub fn new_with(items: &[&'a str], config: QuickMatchConfig) -> Self
Expect the items to be pre-formatted (lowercase)
Sourcepub fn matches(&self, query: &str) -> Vec<&'a str>
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}Sourcepub fn matches_with(
&self,
query: &str,
config: &QuickMatchConfig,
) -> Vec<&'a str>
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§
impl<'a> Send for QuickMatch<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more