Skip to main content

orbtk_utils/
orientation.rs

1/// Is used to control the orientation of the `Stack`.
2#[derive(Debug, Copy, Clone, PartialEq)]
3pub enum Orientation {
4    /// Vertical orientation.
5    Vertical,
6
7    /// Horizontal orientation.
8    Horizontal,
9}
10
11// --- Conversions ---
12
13impl From<&str> for Orientation {
14    fn from(t: &str) -> Self {
15        match t {
16            "Horizontal" | "horizontal" => Orientation::Horizontal,
17            _ => Orientation::Vertical,
18        }
19    }
20}
21
22impl Default for Orientation {
23    fn default() -> Orientation {
24        Orientation::Vertical
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn test_into() {
34        let orientation: Orientation = "Vertical".into();
35        assert_eq!(orientation, Orientation::Vertical);
36
37        let orientation: Orientation = "vertical".into();
38        assert_eq!(orientation, Orientation::Vertical);
39
40        let orientation: Orientation = "Horizontal".into();
41        assert_eq!(orientation, Orientation::Horizontal);
42
43        let orientation: Orientation = "horizontal".into();
44        assert_eq!(orientation, Orientation::Horizontal);
45
46        let orientation: Orientation = "other".into();
47        assert_eq!(orientation, Orientation::Vertical);
48    }
49}