etop_format/number_format/
builder.rs1use super::types::{FormatType, NumberAlign, NumberFormat, Sign, Timezone};
2
3impl NumberFormat {
4 pub fn new() -> NumberFormat {
6 NumberFormat::default()
7 }
8
9 pub fn zero_padding(mut self) -> NumberFormat {
13 self.zero_padding = true;
14 self
15 }
16
17 pub fn no_zero_padding(mut self) -> NumberFormat {
19 self.zero_padding = false;
20 self
21 }
22
23 pub fn fill(mut self, fill_char: char) -> NumberFormat {
27 self.fill = fill_char;
28 self
29 }
30
31 pub fn left_align(mut self) -> NumberFormat {
35 self.align = NumberAlign::Left;
36 self
37 }
38
39 pub fn right_align(mut self) -> NumberFormat {
41 self.align = NumberAlign::Right;
42 self
43 }
44
45 pub fn center_align(mut self) -> NumberFormat {
47 self.align = NumberAlign::Center;
48 self
49 }
50
51 pub fn left_sign_right_align(mut self) -> NumberFormat {
53 self.align = NumberAlign::SignedRight;
54 self
55 }
56
57 pub fn unsigned(mut self) -> NumberFormat {
61 self.sign = Sign::OnlyNegative;
62 self
63 }
64
65 pub fn signed(mut self) -> NumberFormat {
67 self.sign = Sign::Always;
68 self
69 }
70
71 pub fn unsigned_space(mut self) -> NumberFormat {
73 self.sign = Sign::SpaceOrDash;
74 self
75 }
76
77 pub fn type_prefix(mut self) -> NumberFormat {
81 self.type_prefix = true;
82 self
83 }
84
85 pub fn no_type_prefix(mut self) -> NumberFormat {
87 self.type_prefix = false;
88 self
89 }
90
91 pub fn width(mut self, width: usize) -> NumberFormat {
95 self.min_width = width;
96 self.max_width = width;
97 self
98 }
99
100 pub fn min_width(mut self, min_width: usize) -> NumberFormat {
102 self.min_width = min_width;
103 self
104 }
105
106 pub fn max_width(mut self, max_width: usize) -> NumberFormat {
108 self.max_width = max_width;
109 self
110 }
111
112 pub fn width_option(self, width: Option<usize>) -> NumberFormat {
114 self.min_width_option(width).max_width_option(width)
115 }
116
117 pub fn min_width_option(mut self, width: Option<usize>) -> NumberFormat {
119 match width {
120 Some(width) => {
121 self.min_width = width;
122 self
123 }
124 None => self,
125 }
126 }
127
128 pub fn max_width_option(mut self, width: Option<usize>) -> NumberFormat {
130 match width {
131 Some(width) => {
132 self.max_width = width;
133 self
134 }
135 None => self,
136 }
137 }
138
139 pub fn commas(mut self) -> NumberFormat {
143 self.commas = true;
144 self
145 }
146
147 pub fn no_commas(mut self) -> NumberFormat {
149 self.commas = false;
150 self
151 }
152
153 pub fn precision(mut self, precision: usize) -> NumberFormat {
157 self.precision = precision;
158 self
159 }
160
161 pub fn timezone_local(mut self) -> NumberFormat {
165 self.timezone = Timezone::Local;
166 self
167 }
168
169 pub fn timezone_utc(mut self) -> NumberFormat {
171 self.timezone = Timezone::Utc;
172 self
173 }
174
175 pub fn scientific_notation(mut self) -> NumberFormat {
179 self.format_type = FormatType::Exponent;
180 self
181 }
182
183 pub fn si(mut self) -> NumberFormat {
185 self.format_type = FormatType::SI;
186 self
187 }
188
189 pub fn percentage(mut self) -> NumberFormat {
191 self.format_type = FormatType::Percentage;
192 self
193 }
194
195 pub fn binary(mut self) -> NumberFormat {
197 self.format_type = FormatType::Binary;
198 self
199 }
200
201 pub fn octal(mut self) -> NumberFormat {
203 self.format_type = FormatType::Octal;
204 self
205 }
206
207 pub fn hex(mut self) -> NumberFormat {
209 self.format_type = FormatType::Octal;
210 self
211 }
212
213 pub fn integer_oom(mut self) -> NumberFormat {
215 self.format_type = FormatType::IntegerOrderOfMagnitude;
216 self
217 }
218
219 pub fn float_oom(mut self) -> NumberFormat {
221 self.format_type = FormatType::FloatOrderOfMagnitude;
222 self
223 }
224
225 pub fn timestamp(mut self) -> NumberFormat {
227 self.format_type = FormatType::TimestampPretty;
228 self
229 }
230
231 pub fn format_type(mut self, format_type: &FormatType) -> NumberFormat {
233 self.format_type = format_type.clone();
234 self
235 }
236}