Length may need to be added back later, but this is a more natural and type-friendly way of specifying how to format the list.
DJH52CL34NRGNCOD27PO2ZZ7QC6TBL5GAZKY2A5FLX55VJJU3ELQC
impl<L: Localize> Localize for List<L> {
fn localize(&self, context: &Context, buffer: &mut String) {
let list_formatter = context.list_formatter(self.length);
impl<L: Localize> Length for $list_name<L> {
fn len(&self) -> usize {
self.messages.len()
}
}
let localized_messages = self.messages.iter().map(|message| {
let mut buffer = String::new();
message.localize(context, &mut buffer);
impl<L: Localize> Localize for $list_name<L> {
fn localize(&self, context: &Context, buffer: &mut String) {
let list_formatter = context.list_formatter($list_type);
let formatted_list = list_formatter.format(localized_messages);
formatted_list.write_to(buffer).unwrap();
}
buffer
});
let formatted_list = list_formatter.format(localized_messages);
formatted_list.write_to(buffer).unwrap();
}
}
};
list_impl!(AndList, ListType::And);
list_impl!(OrList, ListType::Or);
list_impl!(UnitList, ListType::Unit);
pub fn list_formatter(&self, length: ListLength) -> &ListFormatter {
let index = match length {
ListLength::Wide => 0,
ListLength::Short => 1,
ListLength::Narrow => 2,
_ => unimplemented!(),
pub fn list_formatter(&self, list_type: list::ListType) -> &ListFormatter {
let index = match list_type {
list::ListType::And => 0,
list::ListType::Or => 1,
list::ListType::Unit => 2,
ListFormatter::try_new_and(
ListFormatterPreferences::from(&self.locale),
ListFormatterOptions::default().with_length(length),
)
let preferences = ListFormatterPreferences::from(&self.locale);
let options = ListFormatterOptions::default();
match list_type {
list::ListType::And => ListFormatter::try_new_and(preferences, options),
list::ListType::Or => ListFormatter::try_new_or(preferences, options),
list::ListType::Unit => ListFormatter::try_new_unit(preferences, options),
}
let narrow_list = List::new(items.clone(), ListLength::Narrow);
let short_list = List::new(items.clone(), ListLength::Short);
let wide_list = List::new(items.clone(), ListLength::Wide);
let and_list = AndList::new(items.clone());
let or_list = OrList::new(items.clone());
let unit_list = UnitList::new(items.clone());