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