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