Skip to main content

noninteractive/
noninteractive.rs

1use std::time::Duration;
2
3use matchmaker::noninteractive::get_matches;
4use matchmaker::nucleo::Render;
5use matchmaker::{Result, SSS};
6
7pub fn mm_get_match<T: SSS + Clone + Render>(
8    items: impl IntoIterator<Item = T>,
9    query: &str,
10) -> Option<T> {
11    let mut ret = None;
12    get_matches(items, query, Duration::from_millis(10), |x| {
13        ret = Some(x.clone());
14        true
15    });
16    ret
17}
18
19fn main() -> Result<()> {
20    let items = std::fs::read_dir(".").unwrap().filter_map(|e| match e {
21        Ok(e) => Some(e.file_name().to_string_lossy().to_string()),
22        _ => None,
23    });
24
25    if let Some(m) = mm_get_match(items, ".") {
26        println!("Found: {m}")
27    };
28
29    Ok(())
30}