tabled/features/style/
line.rs

1/// The structure represent a vertical or horizontal line.
2#[derive(Debug, Default, Clone, Copy)]
3pub struct Line {
4    pub(crate) main: Option<char>,
5    pub(crate) intersection: Option<char>,
6    pub(crate) connector1: Option<char>,
7    pub(crate) connector2: Option<char>,
8}
9
10impl Line {
11    /// Creates a new [`Line`] object.
12    pub const fn new(
13        main: Option<char>,
14        intersection: Option<char>,
15        connector1: Option<char>,
16        connector2: Option<char>,
17    ) -> Self {
18        Self {
19            main,
20            intersection,
21            connector1,
22            connector2,
23        }
24    }
25
26    /// Creates a new [`Line`] object with all chars set.
27    pub const fn full(main: char, intersection: char, connector1: char, connector2: char) -> Self {
28        Self::new(
29            Some(main),
30            Some(intersection),
31            Some(connector1),
32            Some(connector2),
33        )
34    }
35
36    /// Creates a new [`Line`] object with all chars set to the provided one.
37    pub const fn filled(c: char) -> Self {
38        Self::full(c, c, c, c)
39    }
40
41    /// Creates a new [`Line`] object with all chars not set.
42    pub const fn empty() -> Self {
43        Self::new(None, None, None, None)
44    }
45
46    /// Checks if the line has nothing set.
47    pub const fn is_empty(&self) -> bool {
48        self.main.is_none()
49            && self.intersection.is_none()
50            && self.connector1.is_none()
51            && self.connector2.is_none()
52    }
53}
54
55impl From<Line> for papergrid::HorizontalLine<char> {
56    fn from(l: Line) -> Self {
57        Self {
58            main: l.main,
59            intersection: l.intersection,
60            left: l.connector1,
61            right: l.connector2,
62        }
63    }
64}
65
66impl From<Line> for papergrid::VerticalLine<char> {
67    fn from(l: Line) -> Self {
68        Self {
69            main: l.main,
70            intersection: l.intersection,
71            top: l.connector1,
72            bottom: l.connector2,
73        }
74    }
75}