rex_app/ui_helper/
shared.rs

1use strsim::normalized_levenshtein;
2
3/// Uses Levenshtein algorithm to get the best match of a string in a vec of strings
4#[must_use]
5pub(crate) fn get_best_match(data: &str, matching_set: &[String]) -> String {
6    let mut best_match = &matching_set[0];
7    let mut best_score = -1.0;
8
9    for x in matching_set {
10        let new_score = normalized_levenshtein(&x.to_lowercase(), &data.to_lowercase());
11
12        if new_score > best_score {
13            best_match = x;
14            best_score = new_score;
15        }
16    }
17    best_match.to_string()
18}
19
20#[derive(Copy, Clone)]
21pub enum StepType {
22    StepUp,
23    StepDown,
24}
25
26#[derive(Copy, Clone)]
27pub enum DateType {
28    Exact,
29    Monthly,
30    Yearly,
31}
32
33impl DateType {
34    pub fn get_next(&mut self) -> Self {
35        match self {
36            DateType::Exact => DateType::Monthly,
37            DateType::Monthly => DateType::Yearly,
38            DateType::Yearly => DateType::Exact,
39        }
40    }
41}