1
2#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
4pub enum Ahom {
5    LetterKa,
7    LetterKha,
9    LetterNga,
11    LetterNa,
13    LetterTa,
15    LetterAlternateTa,
17    LetterPa,
19    LetterPha,
21    LetterBa,
23    LetterMa,
25    LetterJa,
27    LetterCha,
29    LetterTha,
31    LetterRa,
33    LetterLa,
35    LetterSa,
37    LetterNya,
39    LetterHa,
41    LetterA,
43    LetterDa,
45    LetterDha,
47    LetterGa,
49    LetterAlternateGa,
51    LetterGha,
53    LetterBha,
55    LetterJha,
57    LetterAlternateBa,
59    ConsonantSignMedialLa,
61    ConsonantSignMedialRa,
63    ConsonantSignMedialLigatingRa,
65    VowelSignA,
67    VowelSignAa,
69    VowelSignI,
71    VowelSignIi,
73    VowelSignU,
75    VowelSignUu,
77    VowelSignE,
79    VowelSignAw,
81    VowelSignO,
83    VowelSignAi,
85    VowelSignAm,
87    SignKiller,
89    DigitZero,
91    DigitOne,
93    DigitTwo,
95    DigitThree,
97    DigitFour,
99    DigitFive,
101    DigitSix,
103    DigitSeven,
105    DigitEight,
107    DigitNine,
109    NumberTen,
111    NumberTwenty,
113    SignSmallSection,
115    SignSection,
117    SignRulai,
119}
120
121impl Into<char> for Ahom {
122    fn into(self) -> char {
123        match self {
124            Ahom::LetterKa => '𑜀',
125            Ahom::LetterKha => '𑜁',
126            Ahom::LetterNga => '𑜂',
127            Ahom::LetterNa => '𑜃',
128            Ahom::LetterTa => '𑜄',
129            Ahom::LetterAlternateTa => '𑜅',
130            Ahom::LetterPa => '𑜆',
131            Ahom::LetterPha => '𑜇',
132            Ahom::LetterBa => '𑜈',
133            Ahom::LetterMa => '𑜉',
134            Ahom::LetterJa => '𑜊',
135            Ahom::LetterCha => '𑜋',
136            Ahom::LetterTha => '𑜌',
137            Ahom::LetterRa => '𑜍',
138            Ahom::LetterLa => '𑜎',
139            Ahom::LetterSa => '𑜏',
140            Ahom::LetterNya => '𑜐',
141            Ahom::LetterHa => '𑜑',
142            Ahom::LetterA => '𑜒',
143            Ahom::LetterDa => '𑜓',
144            Ahom::LetterDha => '𑜔',
145            Ahom::LetterGa => '𑜕',
146            Ahom::LetterAlternateGa => '𑜖',
147            Ahom::LetterGha => '𑜗',
148            Ahom::LetterBha => '𑜘',
149            Ahom::LetterJha => '𑜙',
150            Ahom::LetterAlternateBa => '𑜚',
151            Ahom::ConsonantSignMedialLa => '𑜝',
152            Ahom::ConsonantSignMedialRa => '𑜞',
153            Ahom::ConsonantSignMedialLigatingRa => '𑜟',
154            Ahom::VowelSignA => '𑜠',
155            Ahom::VowelSignAa => '𑜡',
156            Ahom::VowelSignI => '𑜢',
157            Ahom::VowelSignIi => '𑜣',
158            Ahom::VowelSignU => '𑜤',
159            Ahom::VowelSignUu => '𑜥',
160            Ahom::VowelSignE => '𑜦',
161            Ahom::VowelSignAw => '𑜧',
162            Ahom::VowelSignO => '𑜨',
163            Ahom::VowelSignAi => '𑜩',
164            Ahom::VowelSignAm => '𑜪',
165            Ahom::SignKiller => '𑜫',
166            Ahom::DigitZero => '𑜰',
167            Ahom::DigitOne => '𑜱',
168            Ahom::DigitTwo => '𑜲',
169            Ahom::DigitThree => '𑜳',
170            Ahom::DigitFour => '𑜴',
171            Ahom::DigitFive => '𑜵',
172            Ahom::DigitSix => '𑜶',
173            Ahom::DigitSeven => '𑜷',
174            Ahom::DigitEight => '𑜸',
175            Ahom::DigitNine => '𑜹',
176            Ahom::NumberTen => '𑜺',
177            Ahom::NumberTwenty => '𑜻',
178            Ahom::SignSmallSection => '𑜼',
179            Ahom::SignSection => '𑜽',
180            Ahom::SignRulai => '𑜾',
181        }
182    }
183}
184
185impl std::convert::TryFrom<char> for Ahom {
186    type Error = ();
187    fn try_from(c: char) -> Result<Self, Self::Error> {
188        match c {
189            '𑜀' => Ok(Ahom::LetterKa),
190            '𑜁' => Ok(Ahom::LetterKha),
191            '𑜂' => Ok(Ahom::LetterNga),
192            '𑜃' => Ok(Ahom::LetterNa),
193            '𑜄' => Ok(Ahom::LetterTa),
194            '𑜅' => Ok(Ahom::LetterAlternateTa),
195            '𑜆' => Ok(Ahom::LetterPa),
196            '𑜇' => Ok(Ahom::LetterPha),
197            '𑜈' => Ok(Ahom::LetterBa),
198            '𑜉' => Ok(Ahom::LetterMa),
199            '𑜊' => Ok(Ahom::LetterJa),
200            '𑜋' => Ok(Ahom::LetterCha),
201            '𑜌' => Ok(Ahom::LetterTha),
202            '𑜍' => Ok(Ahom::LetterRa),
203            '𑜎' => Ok(Ahom::LetterLa),
204            '𑜏' => Ok(Ahom::LetterSa),
205            '𑜐' => Ok(Ahom::LetterNya),
206            '𑜑' => Ok(Ahom::LetterHa),
207            '𑜒' => Ok(Ahom::LetterA),
208            '𑜓' => Ok(Ahom::LetterDa),
209            '𑜔' => Ok(Ahom::LetterDha),
210            '𑜕' => Ok(Ahom::LetterGa),
211            '𑜖' => Ok(Ahom::LetterAlternateGa),
212            '𑜗' => Ok(Ahom::LetterGha),
213            '𑜘' => Ok(Ahom::LetterBha),
214            '𑜙' => Ok(Ahom::LetterJha),
215            '𑜚' => Ok(Ahom::LetterAlternateBa),
216            '𑜝' => Ok(Ahom::ConsonantSignMedialLa),
217            '𑜞' => Ok(Ahom::ConsonantSignMedialRa),
218            '𑜟' => Ok(Ahom::ConsonantSignMedialLigatingRa),
219            '𑜠' => Ok(Ahom::VowelSignA),
220            '𑜡' => Ok(Ahom::VowelSignAa),
221            '𑜢' => Ok(Ahom::VowelSignI),
222            '𑜣' => Ok(Ahom::VowelSignIi),
223            '𑜤' => Ok(Ahom::VowelSignU),
224            '𑜥' => Ok(Ahom::VowelSignUu),
225            '𑜦' => Ok(Ahom::VowelSignE),
226            '𑜧' => Ok(Ahom::VowelSignAw),
227            '𑜨' => Ok(Ahom::VowelSignO),
228            '𑜩' => Ok(Ahom::VowelSignAi),
229            '𑜪' => Ok(Ahom::VowelSignAm),
230            '𑜫' => Ok(Ahom::SignKiller),
231            '𑜰' => Ok(Ahom::DigitZero),
232            '𑜱' => Ok(Ahom::DigitOne),
233            '𑜲' => Ok(Ahom::DigitTwo),
234            '𑜳' => Ok(Ahom::DigitThree),
235            '𑜴' => Ok(Ahom::DigitFour),
236            '𑜵' => Ok(Ahom::DigitFive),
237            '𑜶' => Ok(Ahom::DigitSix),
238            '𑜷' => Ok(Ahom::DigitSeven),
239            '𑜸' => Ok(Ahom::DigitEight),
240            '𑜹' => Ok(Ahom::DigitNine),
241            '𑜺' => Ok(Ahom::NumberTen),
242            '𑜻' => Ok(Ahom::NumberTwenty),
243            '𑜼' => Ok(Ahom::SignSmallSection),
244            '𑜽' => Ok(Ahom::SignSection),
245            '𑜾' => Ok(Ahom::SignRulai),
246            _ => Err(()),
247        }
248    }
249}
250
251impl Into<u32> for Ahom {
252    fn into(self) -> u32 {
253        let c: char = self.into();
254        let hex = c
255            .escape_unicode()
256            .to_string()
257            .replace("\\u{", "")
258            .replace("}", "");
259        u32::from_str_radix(&hex, 16).unwrap()
260    }
261}
262
263impl std::convert::TryFrom<u32> for Ahom {
264    type Error = ();
265    fn try_from(u: u32) -> Result<Self, Self::Error> {
266        if let Ok(c) = char::try_from(u) {
267            Self::try_from(c)
268        } else {
269            Err(())
270        }
271    }
272}
273
274impl Iterator for Ahom {
275    type Item = Self;
276    fn next(&mut self) -> Option<Self> {
277        let index: u32 = (*self).into();
278        use std::convert::TryFrom;
279        Self::try_from(index + 1).ok()
280    }
281}
282
283impl Ahom {
284    pub fn new() -> Self {
286        Ahom::LetterKa
287    }
288
289    pub fn name(&self) -> String {
291        let s = std::format!("Ahom{:#?}", self);
292        string_morph::to_sentence_case(&s)
293    }
294}