use crate::locale::{English, Locale};
#[derive(Copy, Clone, Debug)]
pub struct ListOptions<L: Locale = English> {
serial_comma: Option<bool>,
conjunction: Option<&'static str>,
locale: L,
}
impl ListOptions<English> {
#[inline]
pub fn new() -> Self {
Self {
serial_comma: None,
conjunction: None,
locale: English,
}
}
}
impl<L: Locale> Default for ListOptions<L> {
#[inline]
fn default() -> Self {
Self {
serial_comma: None,
conjunction: None,
locale: L::default(),
}
}
}
impl<L: Locale> ListOptions<L> {
#[inline]
pub fn serial_comma(mut self) -> Self {
self.serial_comma = Some(true);
self
}
#[inline]
pub fn serial_comma_enabled(mut self, enabled: bool) -> Self {
self.serial_comma = Some(enabled);
self
}
#[inline]
pub fn no_serial_comma(mut self) -> Self {
self.serial_comma = Some(false);
self
}
#[inline]
pub fn conjunction(mut self, word: &'static str) -> Self {
self.conjunction = Some(word);
self
}
#[inline]
pub fn locale<N: Locale>(self, locale: N) -> ListOptions<N> {
ListOptions {
serial_comma: self.serial_comma,
conjunction: self.conjunction,
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
}
pub(crate) fn conjunction_or<'a>(&'a self, fallback: &'a str) -> &'a str {
self.conjunction.unwrap_or(fallback)
}
}