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
extern crate libc;
extern crate rayon;

mod consts;
mod terminal;

pub mod ansi;
pub mod stdin;
pub mod matcher;
pub mod matrix;
pub mod scorer;
pub mod interface;

pub type Match<'a> = (&'a str, f64);
pub type MatchWithPositions<'a> = (&'a str, f64, Vec<usize>);

pub fn match_and_score<'a>(needle: &str, haystack: &'a str) -> Option<Match<'a>> {
    if matcher::matches(needle, haystack) {
        Some((haystack, scorer::score(needle, haystack)))
    } else {
        None
    }
}

pub fn match_and_score_with_positions<'a>(needle: &str, haystack: &'a str) -> Option<MatchWithPositions<'a>> {
    if matcher::matches(needle, haystack) {
        let (score, positions) = scorer::score_with_positions(needle, haystack);
        Some((haystack, score, positions))
    } else {
        None
    }
}