| 1 | /// A structure for a custom horizontal line. |
| 2 | #[derive (Debug, Clone, Copy, Default, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 3 | pub struct HorizontalLine<T> { |
| 4 | /// Line character. |
| 5 | pub main: Option<T>, |
| 6 | /// Line intersection character. |
| 7 | pub intersection: Option<T>, |
| 8 | /// Left intersection character. |
| 9 | pub left: Option<T>, |
| 10 | /// Right intersection character. |
| 11 | pub right: Option<T>, |
| 12 | } |
| 13 | |
| 14 | impl<T> HorizontalLine<T> { |
| 15 | /// Creates a new line. |
| 16 | pub const fn new( |
| 17 | main: Option<T>, |
| 18 | intersection: Option<T>, |
| 19 | left: Option<T>, |
| 20 | right: Option<T>, |
| 21 | ) -> Self { |
| 22 | Self { |
| 23 | main, |
| 24 | intersection, |
| 25 | left, |
| 26 | right, |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /// Creates a new line. |
| 31 | pub const fn full(main: T, intersection: T, left: T, right: T) -> Self { |
| 32 | Self::new(Some(main), Some(intersection), Some(left), Some(right)) |
| 33 | } |
| 34 | |
| 35 | /// Creates a new line. |
| 36 | pub const fn filled(val: T) -> Self |
| 37 | where |
| 38 | T: Copy, |
| 39 | { |
| 40 | Self { |
| 41 | main: Some(val), |
| 42 | intersection: Some(val), |
| 43 | left: Some(val), |
| 44 | right: Some(val), |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /// Creates a new line. |
| 49 | pub const fn empty() -> Self { |
| 50 | Self::new(None, None, None, None) |
| 51 | } |
| 52 | |
| 53 | /// Verifies if the line has any setting set. |
| 54 | pub const fn is_empty(&self) -> bool { |
| 55 | self.main.is_none() |
| 56 | && self.intersection.is_none() |
| 57 | && self.left.is_none() |
| 58 | && self.right.is_none() |
| 59 | } |
| 60 | } |
| 61 | |