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 Hanunoo block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Hanunoo {
    /// \u{1720}: 'ᜠ'
    LetterA,
    /// \u{1721}: 'ᜡ'
    LetterI,
    /// \u{1722}: 'ᜢ'
    LetterU,
    /// \u{1723}: 'ᜣ'
    LetterKa,
    /// \u{1724}: 'ᜤ'
    LetterGa,
    /// \u{1725}: 'ᜥ'
    LetterNga,
    /// \u{1726}: 'ᜦ'
    LetterTa,
    /// \u{1727}: 'ᜧ'
    LetterDa,
    /// \u{1728}: 'ᜨ'
    LetterNa,
    /// \u{1729}: 'ᜩ'
    LetterPa,
    /// \u{172a}: 'ᜪ'
    LetterBa,
    /// \u{172b}: 'ᜫ'
    LetterMa,
    /// \u{172c}: 'ᜬ'
    LetterYa,
    /// \u{172d}: 'ᜭ'
    LetterRa,
    /// \u{172e}: 'ᜮ'
    LetterLa,
    /// \u{172f}: 'ᜯ'
    LetterWa,
    /// \u{1730}: 'ᜰ'
    LetterSa,
    /// \u{1731}: 'ᜱ'
    LetterHa,
    /// \u{1732}: 'ᜲ'
    VowelSignI,
    /// \u{1733}: 'ᜳ'
    VowelSignU,
    /// \u{1734}: '᜴'
    SignPamudpod,
    /// \u{1735}: '᜵'
    PhilippineSinglePunctuation,
    /// \u{1736}: '᜶'
    PhilippineDoublePunctuation,
}

impl Into<char> for Hanunoo {
    fn into(self) -> char {
        match self {
            Hanunoo::LetterA => '',
            Hanunoo::LetterI => '',
            Hanunoo::LetterU => '',
            Hanunoo::LetterKa => '',
            Hanunoo::LetterGa => '',
            Hanunoo::LetterNga => '',
            Hanunoo::LetterTa => '',
            Hanunoo::LetterDa => '',
            Hanunoo::LetterNa => '',
            Hanunoo::LetterPa => '',
            Hanunoo::LetterBa => '',
            Hanunoo::LetterMa => '',
            Hanunoo::LetterYa => '',
            Hanunoo::LetterRa => '',
            Hanunoo::LetterLa => '',
            Hanunoo::LetterWa => '',
            Hanunoo::LetterSa => '',
            Hanunoo::LetterHa => '',
            Hanunoo::VowelSignI => '',
            Hanunoo::VowelSignU => '',
            Hanunoo::SignPamudpod => '',
            Hanunoo::PhilippineSinglePunctuation => '',
            Hanunoo::PhilippineDoublePunctuation => '',
        }
    }
}

impl std::convert::TryFrom<char> for Hanunoo {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        match c {
            '' => Ok(Hanunoo::LetterA),
            '' => Ok(Hanunoo::LetterI),
            '' => Ok(Hanunoo::LetterU),
            '' => Ok(Hanunoo::LetterKa),
            '' => Ok(Hanunoo::LetterGa),
            '' => Ok(Hanunoo::LetterNga),
            '' => Ok(Hanunoo::LetterTa),
            '' => Ok(Hanunoo::LetterDa),
            '' => Ok(Hanunoo::LetterNa),
            '' => Ok(Hanunoo::LetterPa),
            '' => Ok(Hanunoo::LetterBa),
            '' => Ok(Hanunoo::LetterMa),
            '' => Ok(Hanunoo::LetterYa),
            '' => Ok(Hanunoo::LetterRa),
            '' => Ok(Hanunoo::LetterLa),
            '' => Ok(Hanunoo::LetterWa),
            '' => Ok(Hanunoo::LetterSa),
            '' => Ok(Hanunoo::LetterHa),
            '' => Ok(Hanunoo::VowelSignI),
            '' => Ok(Hanunoo::VowelSignU),
            '' => Ok(Hanunoo::SignPamudpod),
            '' => Ok(Hanunoo::PhilippineSinglePunctuation),
            '' => Ok(Hanunoo::PhilippineDoublePunctuation),
            _ => Err(()),
        }
    }
}

impl Into<u32> for Hanunoo {
    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 Hanunoo {
    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 Hanunoo {
    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 Hanunoo {
    /// The character with the lowest index in this unicode block
    pub fn new() -> Self {
        Hanunoo::LetterA
    }

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