use crate::locale::{English, Locale};
#[derive(Copy, Clone, Debug)]
pub struct DurationOptions<L: Locale = English> {
pub(crate) max_units: u8,
pub(crate) long_units: bool,
pub(crate) locale: L,
}
impl DurationOptions<English> {
#[inline]
pub fn new() -> Self {
Self {
max_units: 2,
long_units: false,
locale: English,
}
}
}
impl<L: Locale> Default for DurationOptions<L> {
#[inline]
fn default() -> Self {
Self {
max_units: 2,
long_units: false,
locale: L::default(),
}
}
}
impl<L: Locale> DurationOptions<L> {
#[inline]
pub fn max_units(mut self, n: u8) -> Self {
self.max_units = n.clamp(1, 7);
self
}
#[inline]
pub fn long_units(mut self) -> Self {
self.long_units = true;
self
}
#[inline]
pub fn locale<N: Locale>(self, locale: N) -> DurationOptions<N> {
DurationOptions {
max_units: self.max_units,
long_units: self.long_units,
locale,
}
}
}