1/// Borders represents a Table frame with horizontal and vertical split lines.
2#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3pub struct Borders<T> {
4 /// A top horizontal on the frame.
5 pub top: Option<T>,
6 /// A top left on the frame.
7 pub top_left: Option<T>,
8 /// A top right on the frame.
9 pub top_right: Option<T>,
10 /// A top horizontal intersection on the frame.
11 pub top_intersection: Option<T>,
12
13 /// A bottom horizontal on the frame.
14 pub bottom: Option<T>,
15 /// A bottom left on the frame.
16 pub bottom_left: Option<T>,
17 /// A bottom right on the frame.
18 pub bottom_right: Option<T>,
19 /// A bottom horizontal intersection on the frame.
20 pub bottom_intersection: Option<T>,
21
22 /// A horizontal split.
23 pub horizontal: Option<T>,
24 /// A vertical split.
25 pub vertical: Option<T>,
26 /// A top left character on the frame.
27 pub intersection: Option<T>,
28
29 /// A vertical split on the left frame line.
30 pub left: Option<T>,
31 /// A horizontal split on the left frame line.
32 pub left_intersection: Option<T>,
33
34 /// A vertical split on the right frame line.
35 pub right: Option<T>,
36 /// A horizontal split on the right frame line.
37 pub right_intersection: Option<T>,
38}
39
40impl<T> Borders<T> {
41 /// Returns empty borders.
42 pub const fn empty() -> Self {
43 Self {
44 top: None,
45 top_left: None,
46 top_right: None,
47 top_intersection: None,
48 bottom: None,
49 bottom_left: None,
50 bottom_right: None,
51 bottom_intersection: None,
52 horizontal: None,
53 left: None,
54 right: None,
55 vertical: None,
56 left_intersection: None,
57 right_intersection: None,
58 intersection: None,
59 }
60 }
61
62 /// Returns Borders filled in with a supplied value.
63 pub const fn filled(val: T) -> Self
64 where
65 T: Copy,
66 {
67 Self {
68 top: Some(val),
69 top_left: Some(val),
70 top_right: Some(val),
71 top_intersection: Some(val),
72 bottom: Some(val),
73 bottom_left: Some(val),
74 bottom_right: Some(val),
75 bottom_intersection: Some(val),
76 horizontal: Some(val),
77 left: Some(val),
78 right: Some(val),
79 vertical: Some(val),
80 left_intersection: Some(val),
81 right_intersection: Some(val),
82 intersection: Some(val),
83 }
84 }
85
86 /// A verification whether any border was set.
87 pub const fn is_empty(&self) -> bool {
88 !(self.top.is_some()
89 || self.top_left.is_some()
90 || self.top_right.is_some()
91 || self.top_intersection.is_some()
92 || self.bottom.is_some()
93 || self.bottom_left.is_some()
94 || self.bottom_right.is_some()
95 || self.bottom_intersection.is_some()
96 || self.horizontal.is_some()
97 || self.left.is_some()
98 || self.right.is_some()
99 || self.vertical.is_some()
100 || self.left_intersection.is_some()
101 || self.right_intersection.is_some()
102 || self.intersection.is_some())
103 }
104
105 /// Verifies if borders has left line set on the frame.
106 pub const fn has_left(&self) -> bool {
107 self.left.is_some()
108 || self.left_intersection.is_some()
109 || self.top_left.is_some()
110 || self.bottom_left.is_some()
111 }
112
113 /// Verifies if borders has right line set on the frame.
114 pub const fn has_right(&self) -> bool {
115 self.right.is_some()
116 || self.right_intersection.is_some()
117 || self.top_right.is_some()
118 || self.bottom_right.is_some()
119 }
120
121 /// Verifies if borders has top line set on the frame.
122 pub const fn has_top(&self) -> bool {
123 self.top.is_some()
124 || self.top_intersection.is_some()
125 || self.top_left.is_some()
126 || self.top_right.is_some()
127 }
128
129 /// Verifies if borders has bottom line set on the frame.
130 pub const fn has_bottom(&self) -> bool {
131 self.bottom.is_some()
132 || self.bottom_intersection.is_some()
133 || self.bottom_left.is_some()
134 || self.bottom_right.is_some()
135 }
136
137 /// Verifies if borders has horizontal lines set.
138 pub const fn has_horizontal(&self) -> bool {
139 self.horizontal.is_some()
140 || self.left_intersection.is_some()
141 || self.right_intersection.is_some()
142 || self.intersection.is_some()
143 }
144
145 /// Verifies if borders has vertical lines set.
146 pub const fn has_vertical(&self) -> bool {
147 self.intersection.is_some()
148 || self.vertical.is_some()
149 || self.top_intersection.is_some()
150 || self.bottom_intersection.is_some()
151 }
152}
153