papergrid/config/
indent.rs

1/// Indent represent a filled space.
2///
3/// # Example
4///
5/// ```
6/// # use papergrid::config::Indent;
7/// let pad = Indent::new(10, ' ');
8/// ```
9#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct Indent {
11    /// A fill character.
12    pub fill: char,
13    /// A number of repeats of a fill character.
14    pub size: usize,
15}
16
17impl Indent {
18    /// Creates a new Indent structure.
19    pub const fn new(size: usize, fill: char) -> Self {
20        Self { fill, size }
21    }
22
23    /// Creates a new Indent structure with space (`' '`) as a fill character.
24    pub const fn spaced(size: usize) -> Self {
25        Self { size, fill: ' ' }
26    }
27
28    /// Creates a new Indent structure with space (`' '`) as a fill character.
29    pub const fn zero() -> Self {
30        Self::new(0, ' ')
31    }
32
33    /// Verifies whether an indent is set to 0.
34    pub const fn is_empty(&self) -> bool {
35        self.size == 0
36    }
37}
38
39impl Default for Indent {
40    fn default() -> Self {
41        Self { size: 0, fill: ' ' }
42    }
43}