russian_numbers 0.2.0

crate for converting numbers into names in Russian language
Documentation
pub trait RevDigits<Digits>
where
    Digits: Iterator<Item = u8>,
{
    /// digits of the number in reverse order
    fn reversed_digits(&self) -> Digits;
    fn into_triplets(&self) -> Triplets<Digits> {
        Triplets::from(self.reversed_digits())
    }
}

/// Three digits in the correct order. Numbers cannot be negative or greater than 9.
#[derive(Debug, Clone, Copy)]
pub struct Triplet([u8; 3]);

impl From<[u8; 3]> for Triplet {
    fn from(arr: [u8; 3]) -> Self {
        debug_assert!(arr.iter().all(|&x| x < 10), "digits must be less then 10");
        Self(arr)
    }
}

impl Triplet {
    /// hundreds
    #[inline]
    pub fn hs(&self) -> u8 {
        self.0[0]
    }
    /// dozens
    #[inline]
    pub fn ds(&self) -> u8 {
        self.0[1]
    }
    /// units
    #[inline]
    pub fn us(&self) -> u8 {
        self.0[2]
    }
    #[inline]
    pub fn ds_us(&self) -> [u8; 2] {
        let [_, ds, us] = self.0;
        [ds, us]
    }
    #[inline]
    pub fn is_sero(&self) -> bool {
        self.0.iter().all(|&x| x == 0)
    }
}

impl AsRef<[u8; 3]> for Triplet {
    #[inline]
    fn as_ref(&self) -> &[u8; 3] {
        &self.0
    }
}

/// Iterator of [triplets](self::Triplet)
/// **Inverted order**
///
/// [1, 2, 3, 3, 2] -> [[3, 2, 1], [0, 2, 3]]
pub struct Triplets<T>(T);

impl<T> From<T> for Triplets<T>
where
    T: Iterator<Item = u8>,
{
    #[inline]
    fn from(reversed_digits: T) -> Self {
        Self(reversed_digits)
    }
}

impl<T> Iterator for Triplets<T>
where
    T: Iterator<Item = u8>,
{
    type Item = Triplet;
    #[inline]
    fn next(&mut self) -> Option<Self::Item> {
        self.0.next().map(|third| {
            let second = self.0.next().unwrap_or_default();
            let first = self.0.next().unwrap_or_default();
            let triplet = [first, second, third];
            triplet.into()
        })
    }
}