Skip to main content

orbtk_utils/
filter.rs

1/// Used to filter stuff such as the `on_changed` callback.
2#[derive(Debug, Clone, PartialEq)]
3pub enum Filter {
4    // Everting will be filtered. No element will be available.
5    Complete,
6
7    // Nothing will be filtered, all elements will be available.
8    Nothing,
9
10    /// Define a list of filtered element.
11    List(Vec<String>),
12}
13
14impl From<&str> for Filter {
15    fn from(s: &str) -> Self {
16        match s {
17            "nothing" | "Nothing" => Filter::Nothing,
18            _ => Filter::Complete,
19        }
20    }
21}
22
23impl From<String> for Filter {
24    fn from(s: String) -> Self {
25        Filter::from(s.as_str())
26    }
27}
28
29impl From<Vec<String>> for Filter {
30    fn from(v: Vec<String>) -> Self {
31        Filter::List(v)
32    }
33}
34
35impl From<Vec<&str>> for Filter {
36    fn from(v: Vec<&str>) -> Self {
37        let vec: Vec<String> = v.iter().map(|s| s.to_string()).collect();
38        Filter::from(vec)
39    }
40}
41
42impl Default for Filter {
43    fn default() -> Self {
44        Filter::Complete
45    }
46}