unicode_types 0.2.0

A mapping of all the unicode characters into convenience types (one enum per block of characters with one variant per character).
Documentation

/// An enum to represent all characters in the Mandaic block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Mandaic {
    /// \u{840}: 'ࡀ'
    LetterHalqa,
    /// \u{841}: 'ࡁ'
    LetterAb,
    /// \u{842}: 'ࡂ'
    LetterAg,
    /// \u{843}: 'ࡃ'
    LetterAd,
    /// \u{844}: 'ࡄ'
    LetterAh,
    /// \u{845}: 'ࡅ'
    LetterUshenna,
    /// \u{846}: 'ࡆ'
    LetterAz,
    /// \u{847}: 'ࡇ'
    LetterIt,
    /// \u{848}: 'ࡈ'
    LetterAtt,
    /// \u{849}: 'ࡉ'
    LetterAksa,
    /// \u{84a}: 'ࡊ'
    LetterAk,
    /// \u{84b}: 'ࡋ'
    LetterAl,
    /// \u{84c}: 'ࡌ'
    LetterAm,
    /// \u{84d}: 'ࡍ'
    LetterAn,
    /// \u{84e}: 'ࡎ'
    LetterAs,
    /// \u{84f}: 'ࡏ'
    LetterIn,
    /// \u{850}: 'ࡐ'
    LetterAp,
    /// \u{851}: 'ࡑ'
    LetterAsz,
    /// \u{852}: 'ࡒ'
    LetterAq,
    /// \u{853}: 'ࡓ'
    LetterAr,
    /// \u{854}: 'ࡔ'
    LetterAsh,
    /// \u{855}: 'ࡕ'
    LetterAt,
    /// \u{856}: 'ࡖ'
    LetterDushenna,
    /// \u{857}: 'ࡗ'
    LetterKad,
    /// \u{858}: 'ࡘ'
    LetterAin,
    /// \u{859}: '࡙'
    AffricationMark,
    /// \u{85a}: '࡚'
    VocalizationMark,
    /// \u{85b}: '࡛'
    GeminationMark,
    /// \u{85e}: '࡞'
    Punctuation,
}

impl Into<char> for Mandaic {
    fn into(self) -> char {
        match self {
            Mandaic::LetterHalqa => '',
            Mandaic::LetterAb => '',
            Mandaic::LetterAg => '',
            Mandaic::LetterAd => '',
            Mandaic::LetterAh => '',
            Mandaic::LetterUshenna => '',
            Mandaic::LetterAz => '',
            Mandaic::LetterIt => '',
            Mandaic::LetterAtt => '',
            Mandaic::LetterAksa => '',
            Mandaic::LetterAk => '',
            Mandaic::LetterAl => '',
            Mandaic::LetterAm => '',
            Mandaic::LetterAn => '',
            Mandaic::LetterAs => '',
            Mandaic::LetterIn => '',
            Mandaic::LetterAp => '',
            Mandaic::LetterAsz => '',
            Mandaic::LetterAq => '',
            Mandaic::LetterAr => '',
            Mandaic::LetterAsh => '',
            Mandaic::LetterAt => '',
            Mandaic::LetterDushenna => '',
            Mandaic::LetterKad => '',
            Mandaic::LetterAin => '',
            Mandaic::AffricationMark => '',
            Mandaic::VocalizationMark => '',
            Mandaic::GeminationMark => '',
            Mandaic::Punctuation => '',
        }
    }
}

impl std::convert::TryFrom<char> for Mandaic {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        match c {
            '' => Ok(Mandaic::LetterHalqa),
            '' => Ok(Mandaic::LetterAb),
            '' => Ok(Mandaic::LetterAg),
            '' => Ok(Mandaic::LetterAd),
            '' => Ok(Mandaic::LetterAh),
            '' => Ok(Mandaic::LetterUshenna),
            '' => Ok(Mandaic::LetterAz),
            '' => Ok(Mandaic::LetterIt),
            '' => Ok(Mandaic::LetterAtt),
            '' => Ok(Mandaic::LetterAksa),
            '' => Ok(Mandaic::LetterAk),
            '' => Ok(Mandaic::LetterAl),
            '' => Ok(Mandaic::LetterAm),
            '' => Ok(Mandaic::LetterAn),
            '' => Ok(Mandaic::LetterAs),
            '' => Ok(Mandaic::LetterIn),
            '' => Ok(Mandaic::LetterAp),
            '' => Ok(Mandaic::LetterAsz),
            '' => Ok(Mandaic::LetterAq),
            '' => Ok(Mandaic::LetterAr),
            '' => Ok(Mandaic::LetterAsh),
            '' => Ok(Mandaic::LetterAt),
            '' => Ok(Mandaic::LetterDushenna),
            '' => Ok(Mandaic::LetterKad),
            '' => Ok(Mandaic::LetterAin),
            '' => Ok(Mandaic::AffricationMark),
            '' => Ok(Mandaic::VocalizationMark),
            '' => Ok(Mandaic::GeminationMark),
            '' => Ok(Mandaic::Punctuation),
            _ => Err(()),
        }
    }
}

impl Into<u32> for Mandaic {
    fn into(self) -> u32 {
        let c: char = self.into();
        let hex = c
            .escape_unicode()
            .to_string()
            .replace("\\u{", "")
            .replace("}", "");
        u32::from_str_radix(&hex, 16).unwrap()
    }
}

impl std::convert::TryFrom<u32> for Mandaic {
    type Error = ();
    fn try_from(u: u32) -> Result<Self, Self::Error> {
        if let Ok(c) = char::try_from(u) {
            Self::try_from(c)
        } else {
            Err(())
        }
    }
}

impl Iterator for Mandaic {
    type Item = Self;
    fn next(&mut self) -> Option<Self> {
        let index: u32 = (*self).into();
        use std::convert::TryFrom;
        Self::try_from(index + 1).ok()
    }
}

impl Mandaic {
    /// The character with the lowest index in this unicode block
    pub fn new() -> Self {
        Mandaic::LetterHalqa
    }

    /// The character's name, in sentence case
    pub fn name(&self) -> String {
        let s = std::format!("Mandaic{:#?}", self);
        string_morph::to_sentence_case(&s)
    }
}