use crate::locale::Locale;
#[derive(Copy, Clone, Debug)]
pub struct BytesOptions {
pub(crate) precision: u8,
pub(crate) binary: bool,
pub(crate) long_units: bool,
pub(crate) decimal_separator: char,
pub(crate) space: bool,
pub(crate) fixed_precision: bool,
}
impl BytesOptions {
#[inline]
pub fn new() -> Self {
Self {
precision: 1,
binary: false,
long_units: false,
decimal_separator: '.',
space: false,
fixed_precision: false,
}
}
#[inline]
pub fn precision(mut self, n: u8) -> Self {
self.precision = n.min(6);
self
}
#[inline]
pub fn binary(mut self) -> Self {
self.binary = true;
self
}
#[inline]
pub fn long_units(mut self) -> Self {
self.long_units = true;
self
}
#[inline]
pub fn space(mut self, enabled: bool) -> Self {
self.space = enabled;
self
}
#[inline]
pub fn decimal_separator(mut self, separator: char) -> Self {
self.decimal_separator = separator;
self
}
#[inline]
pub fn fixed_precision(mut self, yes: bool) -> Self {
self.fixed_precision = yes;
self
}
#[inline]
pub fn locale<L: Locale>(mut self, locale: L) -> Self {
self.decimal_separator = locale.decimal_separator();
self
}
}
impl Default for BytesOptions {
#[inline]
fn default() -> Self {
Self::new()
}
}