use crate::integer::IntegerImpl;
use crate::UnsignedInteger;
use core::fmt::{self, Write};
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct TallyMarks<T>(pub T);
impl<T> From<T> for TallyMarks<T>
where
T: UnsignedInteger,
{
fn from(value: T) -> Self {
TallyMarks(value)
}
}
impl<T> fmt::Display for TallyMarks<T>
where
T: UnsignedInteger,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_tally_marks(self.0.into_impl(), f)
}
}
fn fmt_tally_marks<T: IntegerImpl>(n: T, f: &mut fmt::Formatter<'_>) -> fmt::Result {
const TALLY_MARK_ONE: char = '\u{1D377}';
const TALLY_MARK_FIVE: char = '\u{1D378}';
let (fives, ones) = (n / T::FIVE, n % T::FIVE);
T::range(T::ZERO, fives).try_for_each(|_| f.write_char(TALLY_MARK_FIVE))?;
T::range(T::ZERO, ones).try_for_each(|_| f.write_char(TALLY_MARK_ONE))?;
Ok(())
}