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
pub mod formatter;
pub mod output;
pub mod parsed_value;
pub mod scale_base;
pub use formatter::Formatter;
pub use output::Output;
pub use parsed_value::ParsedValue;
use pipe_trait::Pipe;
#[cfg(feature = "cli")]
use clap::ValueEnum;
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "cli", derive(ValueEnum))]
pub enum BytesFormat {
#[cfg_attr(feature = "cli", clap(name = "plain"))]
PlainNumber,
#[cfg_attr(feature = "cli", clap(name = "metric"))]
MetricUnits,
#[cfg_attr(feature = "cli", clap(name = "binary"))]
BinaryUnits,
}
impl BytesFormat {
pub fn format(self, bytes: u64) -> Output {
use formatter::{BINARY, METRIC};
use BytesFormat::*;
match self {
PlainNumber => Output::PlainNumber(bytes),
MetricUnits => METRIC.parse_value(bytes).pipe(Output::Units),
BinaryUnits => BINARY.parse_value(bytes).pipe(Output::Units),
}
}
}