1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use super::types::{StringAlign, StringFormat};

impl StringFormat {
    /// create new number format
    pub fn new() -> StringFormat {
        StringFormat::default()
    }

    // width

    /// set width
    pub fn width(mut self, width: usize) -> StringFormat {
        self.min_width = width;
        self.max_width = width;
        self
    }

    /// set min_width
    pub fn min_width(mut self, min_width: usize) -> StringFormat {
        self.min_width = min_width;
        self
    }

    /// set max_width
    pub fn max_width(mut self, max_width: usize) -> StringFormat {
        self.max_width = max_width;
        self
    }

    /// set width
    pub fn width_option(self, width: Option<usize>) -> StringFormat {
        self.min_width_option(width).max_width_option(width)
    }

    /// set min_width
    pub fn min_width_option(mut self, width: Option<usize>) -> StringFormat {
        match width {
            Some(width) => {
                self.min_width = width;
                self
            }
            None => self,
        }
    }

    /// set max_width
    pub fn max_width_option(mut self, width: Option<usize>) -> StringFormat {
        match width {
            Some(width) => {
                self.max_width = width;
                self
            }
            None => self,
        }
    }

    // align

    /// left align
    pub fn left_align(mut self) -> StringFormat {
        self.align = StringAlign::Left;
        self
    }

    /// right align
    pub fn right_align(mut self) -> StringFormat {
        self.align = StringAlign::Right;
        self
    }

    // fill char

    /// add fill char
    pub fn fill_char(mut self, fill_char: char) -> StringFormat {
        self.fill_char = fill_char;
        self
    }
}