orbtk_utils/
orientation.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
/// Is used to control the orientation of the `Stack`.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Orientation {
    /// Vertical orientation.
    Vertical,

    /// Horizontal orientation.
    Horizontal,
}

// --- Conversions ---

impl From<&str> for Orientation {
    fn from(t: &str) -> Self {
        match t {
            "Horizontal" | "horizontal" => Orientation::Horizontal,
            _ => Orientation::Vertical,
        }
    }
}

impl Default for Orientation {
    fn default() -> Orientation {
        Orientation::Vertical
    }
}

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

    #[test]
    fn test_into() {
        let orientation: Orientation = "Vertical".into();
        assert_eq!(orientation, Orientation::Vertical);

        let orientation: Orientation = "vertical".into();
        assert_eq!(orientation, Orientation::Vertical);

        let orientation: Orientation = "Horizontal".into();
        assert_eq!(orientation, Orientation::Horizontal);

        let orientation: Orientation = "horizontal".into();
        assert_eq!(orientation, Orientation::Horizontal);

        let orientation: Orientation = "other".into();
        assert_eq!(orientation, Orientation::Vertical);
    }
}