use {super::*, regex::RegexSet}; #[derive(Debug, Copy, Clone)] pub(crate) enum Representation { Address, Decimal, Degree, Hash, InscriptionId, Integer, Name, OutPoint, Percentile, SatPoint, } impl Representation { const fn pattern(self) -> (Self, &'static str) { ( self, match self { Self::Address => r"^(bc|BC|tb|TB|bcrt|BCRT)1.*$", Self::Decimal => r"^.*\..*$", Self::Degree => r"^.*°.*′.*″(.*‴)?$", Self::Hash => r"^[[:xdigit:]]{64}$", Self::InscriptionId => r"^[[:xdigit:]]{64}i\d+$", Self::Integer => r"^[0-9]*$", Self::Name => r"^[a-z]{1,11}$", Self::OutPoint => r"^[[:xdigit:]]{64}:\d+$", Self::Percentile => r"^.*%$", Self::SatPoint => r"^[[:xdigit:]]{64}:\d+:\d+$", }, ) } } impl FromStr for Representation { type Err = Error; fn from_str(s: &str) -> Result { if let Some(i) = REGEX_SET.matches(s).into_iter().next() { Ok(PATTERNS[i].0) } else { Err(anyhow!("unrecognized object"))