etop_format/string_format/
builder.rs

1use super::types::{StringAlign, StringFormat};
2
3impl StringFormat {
4    /// create new number format
5    pub fn new() -> StringFormat {
6        StringFormat::default()
7    }
8
9    // width
10
11    /// set width
12    pub fn width(mut self, width: usize) -> StringFormat {
13        self.min_width = width;
14        self.max_width = width;
15        self
16    }
17
18    /// set min_width
19    pub fn min_width(mut self, min_width: usize) -> StringFormat {
20        self.min_width = min_width;
21        self
22    }
23
24    /// set max_width
25    pub fn max_width(mut self, max_width: usize) -> StringFormat {
26        self.max_width = max_width;
27        self
28    }
29
30    /// set width
31    pub fn width_option(self, width: Option<usize>) -> StringFormat {
32        self.min_width_option(width).max_width_option(width)
33    }
34
35    /// set min_width
36    pub fn min_width_option(mut self, width: Option<usize>) -> StringFormat {
37        match width {
38            Some(width) => {
39                self.min_width = width;
40                self
41            }
42            None => self,
43        }
44    }
45
46    /// set max_width
47    pub fn max_width_option(mut self, width: Option<usize>) -> StringFormat {
48        match width {
49            Some(width) => {
50                self.max_width = width;
51                self
52            }
53            None => self,
54        }
55    }
56
57    // align
58
59    /// left align
60    pub fn left_align(mut self) -> StringFormat {
61        self.align = StringAlign::Left;
62        self
63    }
64
65    /// right align
66    pub fn right_align(mut self) -> StringFormat {
67        self.align = StringAlign::Right;
68        self
69    }
70
71    // fill char
72
73    /// add fill char
74    pub fn fill_char(mut self, fill_char: char) -> StringFormat {
75        self.fill_char = fill_char;
76        self
77    }
78}