1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::fmt::{Display, Error, Formatter};
use std::sync::Arc;

use crate::item::RankBuilder;
use crate::{MatchEngine, MatchRange, MatchResult, SkimItem};

//------------------------------------------------------------------------------
#[derive(Debug)]
pub struct MatchAllEngine {
    rank_builder: Arc<RankBuilder>,
}

impl MatchAllEngine {
    pub fn builder() -> Self {
        Self {
            rank_builder: Default::default(),
        }
    }

    pub fn rank_builder(mut self, rank_builder: Arc<RankBuilder>) -> Self {
        self.rank_builder = rank_builder;
        self
    }

    pub fn build(self) -> Self {
        self
    }
}

impl MatchEngine for MatchAllEngine {
    fn match_item(&self, item: &dyn SkimItem) -> Option<MatchResult> {
        let item_len = item.text().len();
        Some(MatchResult {
            rank: self.rank_builder.build_rank(0, 0, 0, item_len),
            matched_range: MatchRange::ByteRange(0, 0),
        })
    }
}

impl Display for MatchAllEngine {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        write!(f, "Noop")
    }
}