1
2#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
4pub enum Lycian {
5 LetterA,
7 LetterE,
9 LetterB,
11 LetterBh,
13 LetterG,
15 LetterD,
17 LetterI,
19 LetterW,
21 LetterZ,
23 LetterTh,
25 LetterJ,
27 LetterK,
29 LetterQ,
31 LetterL,
33 LetterM,
35 LetterN,
37 LetterMm,
39 LetterNn,
41 LetterU,
43 LetterP,
45 LetterKk,
47 LetterR,
49 LetterS,
51 LetterT,
53 LetterTt,
55 LetterAn,
57 LetterEn,
59 LetterH,
61 LetterX,
63}
64
65impl Into<char> for Lycian {
66 fn into(self) -> char {
67 match self {
68 Lycian::LetterA => '𐊀',
69 Lycian::LetterE => '𐊁',
70 Lycian::LetterB => '𐊂',
71 Lycian::LetterBh => '𐊃',
72 Lycian::LetterG => '𐊄',
73 Lycian::LetterD => '𐊅',
74 Lycian::LetterI => '𐊆',
75 Lycian::LetterW => '𐊇',
76 Lycian::LetterZ => '𐊈',
77 Lycian::LetterTh => '𐊉',
78 Lycian::LetterJ => '𐊊',
79 Lycian::LetterK => '𐊋',
80 Lycian::LetterQ => '𐊌',
81 Lycian::LetterL => '𐊍',
82 Lycian::LetterM => '𐊎',
83 Lycian::LetterN => '𐊏',
84 Lycian::LetterMm => '𐊐',
85 Lycian::LetterNn => '𐊑',
86 Lycian::LetterU => '𐊒',
87 Lycian::LetterP => '𐊓',
88 Lycian::LetterKk => '𐊔',
89 Lycian::LetterR => '𐊕',
90 Lycian::LetterS => '𐊖',
91 Lycian::LetterT => '𐊗',
92 Lycian::LetterTt => '𐊘',
93 Lycian::LetterAn => '𐊙',
94 Lycian::LetterEn => '𐊚',
95 Lycian::LetterH => '𐊛',
96 Lycian::LetterX => '𐊜',
97 }
98 }
99}
100
101impl std::convert::TryFrom<char> for Lycian {
102 type Error = ();
103 fn try_from(c: char) -> Result<Self, Self::Error> {
104 match c {
105 '𐊀' => Ok(Lycian::LetterA),
106 '𐊁' => Ok(Lycian::LetterE),
107 '𐊂' => Ok(Lycian::LetterB),
108 '𐊃' => Ok(Lycian::LetterBh),
109 '𐊄' => Ok(Lycian::LetterG),
110 '𐊅' => Ok(Lycian::LetterD),
111 '𐊆' => Ok(Lycian::LetterI),
112 '𐊇' => Ok(Lycian::LetterW),
113 '𐊈' => Ok(Lycian::LetterZ),
114 '𐊉' => Ok(Lycian::LetterTh),
115 '𐊊' => Ok(Lycian::LetterJ),
116 '𐊋' => Ok(Lycian::LetterK),
117 '𐊌' => Ok(Lycian::LetterQ),
118 '𐊍' => Ok(Lycian::LetterL),
119 '𐊎' => Ok(Lycian::LetterM),
120 '𐊏' => Ok(Lycian::LetterN),
121 '𐊐' => Ok(Lycian::LetterMm),
122 '𐊑' => Ok(Lycian::LetterNn),
123 '𐊒' => Ok(Lycian::LetterU),
124 '𐊓' => Ok(Lycian::LetterP),
125 '𐊔' => Ok(Lycian::LetterKk),
126 '𐊕' => Ok(Lycian::LetterR),
127 '𐊖' => Ok(Lycian::LetterS),
128 '𐊗' => Ok(Lycian::LetterT),
129 '𐊘' => Ok(Lycian::LetterTt),
130 '𐊙' => Ok(Lycian::LetterAn),
131 '𐊚' => Ok(Lycian::LetterEn),
132 '𐊛' => Ok(Lycian::LetterH),
133 '𐊜' => Ok(Lycian::LetterX),
134 _ => Err(()),
135 }
136 }
137}
138
139impl Into<u32> for Lycian {
140 fn into(self) -> u32 {
141 let c: char = self.into();
142 let hex = c
143 .escape_unicode()
144 .to_string()
145 .replace("\\u{", "")
146 .replace("}", "");
147 u32::from_str_radix(&hex, 16).unwrap()
148 }
149}
150
151impl std::convert::TryFrom<u32> for Lycian {
152 type Error = ();
153 fn try_from(u: u32) -> Result<Self, Self::Error> {
154 if let Ok(c) = char::try_from(u) {
155 Self::try_from(c)
156 } else {
157 Err(())
158 }
159 }
160}
161
162impl Iterator for Lycian {
163 type Item = Self;
164 fn next(&mut self) -> Option<Self> {
165 let index: u32 = (*self).into();
166 use std::convert::TryFrom;
167 Self::try_from(index + 1).ok()
168 }
169}
170
171impl Lycian {
172 pub fn new() -> Self {
174 Lycian::LetterA
175 }
176
177 pub fn name(&self) -> String {
179 let s = std::format!("Lycian{:#?}", self);
180 string_morph::to_sentence_case(&s)
181 }
182}