orbtk_utils/
selection_mode.rs

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
45
46
47
48
49
50
51
52
/// Represents a selection mode.
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum SelectionMode {
    None,
    Single,
    Multiple,
}

impl Default for SelectionMode {
    fn default() -> Self {
        SelectionMode::Single
    }
}

impl From<&str> for SelectionMode {
    fn from(t: &str) -> Self {
        match t {
            "Single" | "single" => SelectionMode::Single,
            "Multiple" | "multiple" => SelectionMode::Multiple,
            _ => SelectionMode::None,
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::prelude::*;

    #[test]
    fn test_into() {
        let selection_mode: SelectionMode = "Single".into();
        assert_eq!(selection_mode, SelectionMode::Single);

        let selection_mode: SelectionMode = "single".into();
        assert_eq!(selection_mode, SelectionMode::Single);

        let selection_mode: SelectionMode = "Multiple".into();
        assert_eq!(selection_mode, SelectionMode::Multiple);

        let selection_mode: SelectionMode = "multiple".into();
        assert_eq!(selection_mode, SelectionMode::Multiple);

        let selection_mode: SelectionMode = "None".into();
        assert_eq!(selection_mode, SelectionMode::None);

        let selection_mode: SelectionMode = "none".into();
        assert_eq!(selection_mode, SelectionMode::None);

        let selection_mode: SelectionMode = "other".into();
        assert_eq!(selection_mode, SelectionMode::None);
    }
}