use std::fmt;
use crate::output::wrapping::NBSP;
pub struct Pluralized<'t, 's> {
count: usize,
thing: &'t str,
plural_suffix: &'s str,
}
impl fmt::Display for Pluralized<'_, '_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}{}{}{}",
self.count,
NBSP,
self.thing,
if self.count == 1 { "" } else { self.plural_suffix })
}
}
impl<'t, 's> Pluralized<'t, 's> {
pub fn plural<'n>(self, suffix: &'n str) -> Pluralized<'t, 'n> {
Pluralized {
count: self.count,
thing: self.thing,
plural_suffix: suffix,
}
}
}
pub trait Pluralize<'t> {
fn of(self, thing: &'t str) -> Pluralized<'t, 'static>;
}
impl<'t> Pluralize<'t> for usize {
fn of(self, thing: &'t str) -> Pluralized<'t, 'static> {
Pluralized {
count: self,
thing: thing,
plural_suffix: "s",
}
}
}