use crate::locale::{English, Locale};
#[derive(Copy, Clone, Debug)]
pub struct ListOptions<L: Locale = English> {
serial_comma: Option<bool>,
locale: L,
}
impl ListOptions<English> {
pub fn new() -> Self {
Self {
serial_comma: None,
locale: English,
}
}
}
impl<L: Locale> Default for ListOptions<L> {
fn default() -> Self {
Self {
serial_comma: None,
locale: L::default(),
}
}
}
impl<L: Locale> ListOptions<L> {
pub fn serial_comma(mut self) -> Self {
self.serial_comma = Some(true);
self
}
pub fn no_serial_comma(mut self) -> Self {
self.serial_comma = Some(false);
self
}
pub fn locale<N: Locale>(self, locale: N) -> ListOptions<N> {
ListOptions {
serial_comma: self.serial_comma,
locale,
}
}
pub(crate) fn serial_comma_value(&self) -> bool {
self.serial_comma
.unwrap_or_else(|| self.locale.serial_comma())
}
pub(crate) fn locale_ref(&self) -> &L {
&self.locale
}
}