(query: &str, target: &str)
| 5 | use nucleo_matcher::{Config, Matcher, Utf32Str}; |
| 6 | |
| 7 | pub fn fuzzy_match(query: &str, target: &str) -> Option<i32> { |
| 8 | let trimmed = query.trim(); |
| 9 | if trimmed.is_empty() { |
| 10 | return Some(0); |
| 11 | } |
| 12 | |
| 13 | let pattern = Pattern::parse(trimmed, CaseMatching::Ignore, Normalization::Smart); |
| 14 | let mut matcher = Matcher::new(Config::DEFAULT); |
| 15 | let mut utf32_buf = Vec::new(); |
| 16 | pattern |
| 17 | .score(Utf32Str::new(target, &mut utf32_buf), &mut matcher) |
| 18 | .map(|score| score.min(i32::MAX as u32) as i32) |
| 19 | } |
| 20 | |
| 21 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
| 22 | pub enum CommandCategory { |
no test coverage detected