etop_format/binary_format/
builder.rs

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