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