matchmaker/nucleo/
mod.rs

1pub mod injector;
2mod worker;
3pub mod query;
4pub mod variants;
5
6use std::{fmt::{self, Display, Formatter}, sync::Arc};
7
8pub use variants::*;
9pub use worker::*;
10
11pub use ratatui::{
12    style::{Style, Stylize},
13    text::{Line, Span, Text},
14};
15
16use crate::SegmentableItem;
17
18// ------------- Wrapper structs
19
20
21/// This struct implements ColumnIndexable, and can instantiate a worker with columns.
22#[derive(Debug, Clone, Hash, Eq, PartialEq)]
23pub struct Segmented<T: SegmentableItem> {
24    pub inner: T,
25    ranges: Arc<[(usize, usize)]>,
26}
27
28impl<T: SegmentableItem> ColumnIndexable for Segmented<T> {
29    fn index(&self, index: usize) -> &str {
30        if let Some((start, end)) = self.ranges.get(index) {
31            &self.inner[*start..*end]
32        } else {
33            ""
34        }
35    }
36}
37
38#[derive(Debug, Clone, Hash, Eq, PartialEq)]
39pub struct Indexed<T> {
40    pub index: u32,
41    pub inner: T,
42}
43
44impl<T: Clone> Indexed<T> {
45
46    /// Matchmaker requires a way to store and identify selected items from their references in the nucleo matcher. This method simply stores the clones of the items.
47    pub fn identifier(&self) -> (u32, T) {
48        (self.index, self.inner.clone())
49    }
50}
51
52impl<T: ColumnIndexable> ColumnIndexable for Indexed<T> {
53    fn index(&self, index: usize) -> &str {
54        self.inner.index(index)
55    }
56}
57
58// ------------------------------------------
59impl<T: Display + SegmentableItem> Display for Segmented<T> {
60    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
61        write!(f, "{}", self.inner)
62    }
63}
64
65impl<T: Display> Display for Indexed<T> {
66    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
67        write!(f, "{}", self.inner)
68    }
69}