use std::fmt;
use std::ops::Deref;
use super::{Currency, Postfix, Prefix};
macro_rules! impl_deref_to_currency {
($s:ty) => {
impl<'a> Deref for $s {
type Target = Currency;
fn deref(&self) -> &Currency {
&self.money
}
}
};
}
impl_deref_to_currency!(Postfix<'a>);
impl_deref_to_currency!(Prefix<'a>);
impl<'a> fmt::Display for Postfix<'a> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let decimal = format!("{:.2}", (self.value as f32 / 100.0)).replace(".", ",");
match self.symbol {
Some(symbol) => write!(f, "{d}{s}", s = symbol, d = decimal),
None => write!(f, "{}", decimal),
}
}
}
impl<'a> fmt::Display for Prefix<'a> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let decimal = format!("{:.2}", (self.value as f32 / 100.0));
match self.symbol {
Some(symbol) => write!(f, "{s}{d}", s = symbol, d = decimal),
None => write!(f, "{}", decimal),
}
}
}