use fixed_decimal::UnsignedDecimal;
use icu_plurals::PluralOperands;
use writeable::Writeable;
use crate::{
CompactDecimalFormatter, DecimalFormatter, FormattedSign, FormattedUnsignedCompactDecimal,
FormattedUnsignedDecimal,
};
pub trait Sealed {}
pub trait AbstractFormatter: core::fmt::Debug + Sealed {
#[doc(hidden)]
type FormattedUnsigned<'a>: Writeable
where
Self: 'a;
#[doc(hidden)]
fn format_unsigned<'a>(&'a self, value: UnsignedDecimal) -> Self::FormattedUnsigned<'a>;
#[doc(hidden)]
fn format_sign<'a, W: Writeable>(
&'a self,
value: W,
sign: fixed_decimal::Sign,
) -> FormattedSign<'a, W>;
#[doc(hidden)]
fn plural_operands(value: &Self::FormattedUnsigned<'_>) -> PluralOperands;
}
impl Sealed for DecimalFormatter {}
impl AbstractFormatter for DecimalFormatter {
type FormattedUnsigned<'a> = FormattedUnsignedDecimal<'a>;
fn format_unsigned<'a>(&'a self, value: UnsignedDecimal) -> Self::FormattedUnsigned<'a> {
self.format_unsigned(crate::Cow::Owned(value))
}
fn format_sign<'a, W: Writeable>(
&'a self,
value: W,
sign: fixed_decimal::Sign,
) -> FormattedSign<'a, W> {
self.format_sign(sign, value)
}
fn plural_operands(value: &Self::FormattedUnsigned<'_>) -> PluralOperands {
value.plural_operands()
}
}
impl Sealed for CompactDecimalFormatter {}
impl AbstractFormatter for CompactDecimalFormatter {
type FormattedUnsigned<'a> = FormattedUnsignedCompactDecimal<'a>;
fn format_unsigned<'a>(&'a self, value: UnsignedDecimal) -> Self::FormattedUnsigned<'a> {
self.format_unsigned(&value)
}
fn format_sign<'a, W: Writeable>(
&'a self,
value: W,
sign: fixed_decimal::Sign,
) -> FormattedSign<'a, W> {
self.decimal_formatter.format_sign(sign, value)
}
fn plural_operands(value: &Self::FormattedUnsigned<'_>) -> PluralOperands {
value.plural_operands()
}
}