1mod defaults;
5pub use self::defaults::*;
6
7#[derive(Debug, PartialEq, Eq, Copy, Clone)]
8pub enum Kilo {
10 Decimal,
12 Binary,
14}
15
16impl Default for Kilo {
17 fn default() -> Self {
18 Self::Decimal
19 }
20}
21
22impl Kilo {
23 pub(crate) fn value(&self) -> f64 {
24 match self {
25 Kilo::Decimal => 1000.0,
26 Kilo::Binary => 1024.0,
27 }
28 }
29}
30
31#[derive(Debug, Copy, Clone)]
32pub enum FixedAt {
34 Base,
35 Kilo,
36 Mega,
37 Giga,
38 Tera,
39 Peta,
40 Exa,
41 Zetta,
42 Yotta,
43}
44
45#[derive(Debug, Copy, Clone, PartialEq)]
46pub enum BaseUnit {
47 Bit,
48 Byte,
49}
50
51impl Default for BaseUnit {
52 fn default() -> Self {
53 Self::Byte
54 }
55}
56
57#[derive(Debug, Clone, Copy, Default)]
59#[non_exhaustive]
60pub struct FormatSizeOptionsBuilder {
61 pub base_unit: BaseUnit,
63
64 pub kilo: Kilo,
66
67 pub units: Kilo,
69
70 pub decimal_places: usize,
72
73 pub decimal_zeroes: usize,
75
76 pub fixed_at: Option<FixedAt>,
78
79 pub long_units: bool,
81
82 pub space_after_value: bool,
84
85 pub suffix: &'static str,
87}
88
89#[derive(Debug, Clone, Copy, Default)]
91#[non_exhaustive]
92pub struct FormatSizeOptions {
93 pub base_unit: BaseUnit,
95
96 pub kilo: Kilo,
98
99 pub units: Kilo,
101
102 pub decimal_places: usize,
104
105 pub decimal_zeroes: usize,
107
108 pub fixed_at: Option<FixedAt>,
110
111 pub long_units: bool,
113
114 pub space_after_value: bool,
116
117 pub suffix: &'static str,
119}
120
121impl FormatSizeOptions {
122 pub fn from(from: FormatSizeOptions) -> FormatSizeOptions {
123 FormatSizeOptions { ..from }
124 }
125
126 pub fn base_unit(mut self, base_unit: BaseUnit) -> FormatSizeOptions {
127 self.base_unit = base_unit;
128 self
129 }
130
131 pub fn kilo(mut self, kilo: Kilo) -> FormatSizeOptions {
132 self.kilo = kilo;
133 self
134 }
135
136 pub fn units(mut self, units: Kilo) -> FormatSizeOptions {
137 self.units = units;
138 self
139 }
140
141 pub fn decimal_places(mut self, decimal_places: usize) -> FormatSizeOptions {
142 self.decimal_places = decimal_places;
143 self
144 }
145
146 pub fn decimal_zeroes(mut self, decimal_zeroes: usize) -> FormatSizeOptions {
147 self.decimal_zeroes = decimal_zeroes;
148 self
149 }
150
151 pub fn fixed_at(mut self, fixed_at: Option<FixedAt>) -> FormatSizeOptions {
152 self.fixed_at = fixed_at;
153 self
154 }
155
156 pub fn long_units(mut self, long_units: bool) -> FormatSizeOptions {
157 self.long_units = long_units;
158 self
159 }
160
161 pub fn space_after_value(mut self, insert_space: bool) -> FormatSizeOptions {
162 self.space_after_value = insert_space;
163 self
164 }
165
166 pub fn suffix(mut self, suffix: &'static str) -> FormatSizeOptions {
167 self.suffix = suffix;
168 self
169 }
170}
171
172impl AsRef<FormatSizeOptions> for FormatSizeOptions {
173 fn as_ref(&self) -> &FormatSizeOptions {
174 self
175 }
176}