parallel_disk_usage/
bytes_format.rspub 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", help = "Display plain number of bytes without units")
)]
PlainNumber,
#[cfg_attr(
feature = "cli",
clap(
name = "metric",
help = "Use metric scale, i.e. 1K = 1000B, 1M = 1000K, and so on",
)
)]
MetricUnits,
#[cfg_attr(
feature = "cli",
clap(
name = "binary",
help = "Use binary scale, i.e. 1K = 1024B, 1M = 1024K, and so on",
)
)]
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),
}
}
}