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
pub trait KeyFilter<V: ?Sized> {
    fn filter(&self, value: &V) -> bool;
}

impl KeyFilter<str> for str {
    fn filter(&self, value: &str) -> bool {
        value.contains(self)
    }
}

impl KeyFilter<str> for Vec<String> {
    fn filter(&self, value: &str) -> bool {
        if self.is_empty() {
            return true;
        }
        self.iter().filter(|key| key.filter(value)).count() > 0
    }
}

#[cfg(test)]
mod tests {

    use super::KeyFilter;

    #[test]
    fn test_str_filter() {
        let value = "quick brown";
        assert!("quick".filter(value));
    }

    #[test]
    fn test_str_list_filter() {
        let value = "quick brown";
        assert!(vec![].filter(value));
        assert!(vec!["quick".to_owned()].filter(value));
    }
}