1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/// A number of constants to give a name to all characters in this block.
mod constants {
    /// \u{10fe0}: '𐿠'
    pub const LETTER_ALEPH: char = '𐿠';
    /// \u{10fe1}: '𐿡'
    pub const LETTER_BETH: char = '𐿡';
    /// \u{10fe2}: '𐿢'
    pub const LETTER_GIMEL: char = '𐿢';
    /// \u{10fe3}: '𐿣'
    pub const LETTER_DALETH: char = '𐿣';
    /// \u{10fe4}: '𐿤'
    pub const LETTER_HE: char = '𐿤';
    /// \u{10fe5}: '𐿥'
    pub const LETTER_WAW: char = '𐿥';
    /// \u{10fe6}: '𐿦'
    pub const LETTER_ZAYIN: char = '𐿦';
    /// \u{10fe7}: '𐿧'
    pub const LETTER_HETH: char = '𐿧';
    /// \u{10fe8}: '𐿨'
    pub const LETTER_TETH: char = '𐿨';
    /// \u{10fe9}: '𐿩'
    pub const LETTER_YODH: char = '𐿩';
    /// \u{10fea}: '𐿪'
    pub const LETTER_KAPH: char = '𐿪';
    /// \u{10feb}: '𐿫'
    pub const LETTER_LAMEDH: char = '𐿫';
    /// \u{10fec}: '𐿬'
    pub const LETTER_MEM: char = '𐿬';
    /// \u{10fed}: '𐿭'
    pub const LETTER_NUN: char = '𐿭';
    /// \u{10fee}: '𐿮'
    pub const LETTER_SAMEKH: char = '𐿮';
    /// \u{10fef}: '𐿯'
    pub const LETTER_AYIN: char = '𐿯';
    /// \u{10ff0}: '𐿰'
    pub const LETTER_PE: char = '𐿰';
    /// \u{10ff1}: '𐿱'
    pub const LETTER_SADHE: char = '𐿱';
    /// \u{10ff2}: '𐿲'
    pub const LETTER_QOPH: char = '𐿲';
    /// \u{10ff3}: '𐿳'
    pub const LETTER_RESH: char = '𐿳';
    /// \u{10ff4}: '𐿴'
    pub const LETTER_SHIN: char = '𐿴';
    /// \u{10ff5}: '𐿵'
    pub const LETTER_TAW: char = '𐿵';
    /// \u{10ff6}: '𐿶'
    pub const LIGATURE_ZAYIN_DASH_YODH: char = '𐿶';
}

/// An enum to represent all characters in the Elymaic block.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum Elymaic {
    /// \u{10fe0}: '𐿠'
    LetterAleph,
    /// \u{10fe1}: '𐿡'
    LetterBeth,
    /// \u{10fe2}: '𐿢'
    LetterGimel,
    /// \u{10fe3}: '𐿣'
    LetterDaleth,
    /// \u{10fe4}: '𐿤'
    LetterHe,
    /// \u{10fe5}: '𐿥'
    LetterWaw,
    /// \u{10fe6}: '𐿦'
    LetterZayin,
    /// \u{10fe7}: '𐿧'
    LetterHeth,
    /// \u{10fe8}: '𐿨'
    LetterTeth,
    /// \u{10fe9}: '𐿩'
    LetterYodh,
    /// \u{10fea}: '𐿪'
    LetterKaph,
    /// \u{10feb}: '𐿫'
    LetterLamedh,
    /// \u{10fec}: '𐿬'
    LetterMem,
    /// \u{10fed}: '𐿭'
    LetterNun,
    /// \u{10fee}: '𐿮'
    LetterSamekh,
    /// \u{10fef}: '𐿯'
    LetterAyin,
    /// \u{10ff0}: '𐿰'
    LetterPe,
    /// \u{10ff1}: '𐿱'
    LetterSadhe,
    /// \u{10ff2}: '𐿲'
    LetterQoph,
    /// \u{10ff3}: '𐿳'
    LetterResh,
    /// \u{10ff4}: '𐿴'
    LetterShin,
    /// \u{10ff5}: '𐿵'
    LetterTaw,
    /// \u{10ff6}: '𐿶'
    LigatureZayinDashYodh,
}

impl Into<char> for Elymaic {
    fn into(self) -> char {
        use constants::*;
        match self {
            Elymaic::LetterAleph => LETTER_ALEPH,
            Elymaic::LetterBeth => LETTER_BETH,
            Elymaic::LetterGimel => LETTER_GIMEL,
            Elymaic::LetterDaleth => LETTER_DALETH,
            Elymaic::LetterHe => LETTER_HE,
            Elymaic::LetterWaw => LETTER_WAW,
            Elymaic::LetterZayin => LETTER_ZAYIN,
            Elymaic::LetterHeth => LETTER_HETH,
            Elymaic::LetterTeth => LETTER_TETH,
            Elymaic::LetterYodh => LETTER_YODH,
            Elymaic::LetterKaph => LETTER_KAPH,
            Elymaic::LetterLamedh => LETTER_LAMEDH,
            Elymaic::LetterMem => LETTER_MEM,
            Elymaic::LetterNun => LETTER_NUN,
            Elymaic::LetterSamekh => LETTER_SAMEKH,
            Elymaic::LetterAyin => LETTER_AYIN,
            Elymaic::LetterPe => LETTER_PE,
            Elymaic::LetterSadhe => LETTER_SADHE,
            Elymaic::LetterQoph => LETTER_QOPH,
            Elymaic::LetterResh => LETTER_RESH,
            Elymaic::LetterShin => LETTER_SHIN,
            Elymaic::LetterTaw => LETTER_TAW,
            Elymaic::LigatureZayinDashYodh => LIGATURE_ZAYIN_DASH_YODH,
        }
    }
}

impl std::convert::TryFrom<char> for Elymaic {
    type Error = ();
    fn try_from(c: char) -> Result<Self, Self::Error> {
        use constants::*;
        match c {
            LETTER_ALEPH => Ok(Elymaic::LetterAleph),
            LETTER_BETH => Ok(Elymaic::LetterBeth),
            LETTER_GIMEL => Ok(Elymaic::LetterGimel),
            LETTER_DALETH => Ok(Elymaic::LetterDaleth),
            LETTER_HE => Ok(Elymaic::LetterHe),
            LETTER_WAW => Ok(Elymaic::LetterWaw),
            LETTER_ZAYIN => Ok(Elymaic::LetterZayin),
            LETTER_HETH => Ok(Elymaic::LetterHeth),
            LETTER_TETH => Ok(Elymaic::LetterTeth),
            LETTER_YODH => Ok(Elymaic::LetterYodh),
            LETTER_KAPH => Ok(Elymaic::LetterKaph),
            LETTER_LAMEDH => Ok(Elymaic::LetterLamedh),
            LETTER_MEM => Ok(Elymaic::LetterMem),
            LETTER_NUN => Ok(Elymaic::LetterNun),
            LETTER_SAMEKH => Ok(Elymaic::LetterSamekh),
            LETTER_AYIN => Ok(Elymaic::LetterAyin),
            LETTER_PE => Ok(Elymaic::LetterPe),
            LETTER_SADHE => Ok(Elymaic::LetterSadhe),
            LETTER_QOPH => Ok(Elymaic::LetterQoph),
            LETTER_RESH => Ok(Elymaic::LetterResh),
            LETTER_SHIN => Ok(Elymaic::LetterShin),
            LETTER_TAW => Ok(Elymaic::LetterTaw),
            LIGATURE_ZAYIN_DASH_YODH => Ok(Elymaic::LigatureZayinDashYodh),
            _ => Err(()),
        }
    }
}

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

    /// The character's name, all lowercase and space-separated
    pub fn name(&self) -> &str {
        match self {
            Elymaic::LetterAleph => "elymaic letter aleph",
            Elymaic::LetterBeth => "elymaic letter beth",
            Elymaic::LetterGimel => "elymaic letter gimel",
            Elymaic::LetterDaleth => "elymaic letter daleth",
            Elymaic::LetterHe => "elymaic letter he",
            Elymaic::LetterWaw => "elymaic letter waw",
            Elymaic::LetterZayin => "elymaic letter zayin",
            Elymaic::LetterHeth => "elymaic letter heth",
            Elymaic::LetterTeth => "elymaic letter teth",
            Elymaic::LetterYodh => "elymaic letter yodh",
            Elymaic::LetterKaph => "elymaic letter kaph",
            Elymaic::LetterLamedh => "elymaic letter lamedh",
            Elymaic::LetterMem => "elymaic letter mem",
            Elymaic::LetterNun => "elymaic letter nun",
            Elymaic::LetterSamekh => "elymaic letter samekh",
            Elymaic::LetterAyin => "elymaic letter ayin",
            Elymaic::LetterPe => "elymaic letter pe",
            Elymaic::LetterSadhe => "elymaic letter sadhe",
            Elymaic::LetterQoph => "elymaic letter qoph",
            Elymaic::LetterResh => "elymaic letter resh",
            Elymaic::LetterShin => "elymaic letter shin",
            Elymaic::LetterTaw => "elymaic letter taw",
            Elymaic::LigatureZayinDashYodh => "elymaic ligature zayin-yodh",
        }
    }
}