#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum PsalterPahlavi {
LetterAleph,
LetterBeth,
LetterGimel,
LetterDaleth,
LetterHe,
LetterWawDashAyinDashResh,
LetterZayin,
LetterHeth,
LetterYodh,
LetterKaph,
LetterLamedh,
LetterMemDashQoph,
LetterNun,
LetterSamekh,
LetterPe,
LetterSadhe,
LetterShin,
LetterTaw,
SectionMark,
TurnedSectionMark,
FourDotsWithCross,
FourDotsWithDot,
NumberOne,
NumberTwo,
NumberThree,
NumberFour,
NumberTen,
NumberTwenty,
}
impl Into<char> for PsalterPahlavi {
fn into(self) -> char {
match self {
PsalterPahlavi::LetterAleph => '𐮀',
PsalterPahlavi::LetterBeth => '𐮁',
PsalterPahlavi::LetterGimel => '𐮂',
PsalterPahlavi::LetterDaleth => '𐮃',
PsalterPahlavi::LetterHe => '𐮄',
PsalterPahlavi::LetterWawDashAyinDashResh => '𐮅',
PsalterPahlavi::LetterZayin => '𐮆',
PsalterPahlavi::LetterHeth => '𐮇',
PsalterPahlavi::LetterYodh => '𐮈',
PsalterPahlavi::LetterKaph => '𐮉',
PsalterPahlavi::LetterLamedh => '𐮊',
PsalterPahlavi::LetterMemDashQoph => '𐮋',
PsalterPahlavi::LetterNun => '𐮌',
PsalterPahlavi::LetterSamekh => '𐮍',
PsalterPahlavi::LetterPe => '𐮎',
PsalterPahlavi::LetterSadhe => '𐮏',
PsalterPahlavi::LetterShin => '𐮐',
PsalterPahlavi::LetterTaw => '𐮑',
PsalterPahlavi::SectionMark => '𐮙',
PsalterPahlavi::TurnedSectionMark => '𐮚',
PsalterPahlavi::FourDotsWithCross => '𐮛',
PsalterPahlavi::FourDotsWithDot => '𐮜',
PsalterPahlavi::NumberOne => '𐮩',
PsalterPahlavi::NumberTwo => '𐮪',
PsalterPahlavi::NumberThree => '𐮫',
PsalterPahlavi::NumberFour => '𐮬',
PsalterPahlavi::NumberTen => '𐮭',
PsalterPahlavi::NumberTwenty => '𐮮',
}
}
}
impl std::convert::TryFrom<char> for PsalterPahlavi {
type Error = ();
fn try_from(c: char) -> Result<Self, Self::Error> {
match c {
'𐮀' => Ok(PsalterPahlavi::LetterAleph),
'𐮁' => Ok(PsalterPahlavi::LetterBeth),
'𐮂' => Ok(PsalterPahlavi::LetterGimel),
'𐮃' => Ok(PsalterPahlavi::LetterDaleth),
'𐮄' => Ok(PsalterPahlavi::LetterHe),
'𐮅' => Ok(PsalterPahlavi::LetterWawDashAyinDashResh),
'𐮆' => Ok(PsalterPahlavi::LetterZayin),
'𐮇' => Ok(PsalterPahlavi::LetterHeth),
'𐮈' => Ok(PsalterPahlavi::LetterYodh),
'𐮉' => Ok(PsalterPahlavi::LetterKaph),
'𐮊' => Ok(PsalterPahlavi::LetterLamedh),
'𐮋' => Ok(PsalterPahlavi::LetterMemDashQoph),
'𐮌' => Ok(PsalterPahlavi::LetterNun),
'𐮍' => Ok(PsalterPahlavi::LetterSamekh),
'𐮎' => Ok(PsalterPahlavi::LetterPe),
'𐮏' => Ok(PsalterPahlavi::LetterSadhe),
'𐮐' => Ok(PsalterPahlavi::LetterShin),
'𐮑' => Ok(PsalterPahlavi::LetterTaw),
'𐮙' => Ok(PsalterPahlavi::SectionMark),
'𐮚' => Ok(PsalterPahlavi::TurnedSectionMark),
'𐮛' => Ok(PsalterPahlavi::FourDotsWithCross),
'𐮜' => Ok(PsalterPahlavi::FourDotsWithDot),
'𐮩' => Ok(PsalterPahlavi::NumberOne),
'𐮪' => Ok(PsalterPahlavi::NumberTwo),
'𐮫' => Ok(PsalterPahlavi::NumberThree),
'𐮬' => Ok(PsalterPahlavi::NumberFour),
'𐮭' => Ok(PsalterPahlavi::NumberTen),
'𐮮' => Ok(PsalterPahlavi::NumberTwenty),
_ => Err(()),
}
}
}
impl Into<u32> for PsalterPahlavi {
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 PsalterPahlavi {
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 PsalterPahlavi {
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 PsalterPahlavi {
pub fn new() -> Self {
PsalterPahlavi::LetterAleph
}
pub fn name(&self) -> String {
let s = std::format!("PsalterPahlavi{:#?}", self);
string_morph::to_sentence_case(&s)
}
}