} } impl Display for InscriptionId { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "{}i{}", self.txid, self.index) } } #[derive(Debug)] pub enum ParseError { Character(char), Length(usize), Separator(char), Txid(bitcoin::hashes::hex::Error), Index(std::num::ParseIntError), } impl Display for ParseError { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { Self::Character(c) => write!(f, "invalid character: '{c}'"), Self::Length(len) => write!(f, "invalid length: {len}"), Self::Separator(c) => write!(f, "invalid seprator: `{c}`"), Self::Txid(err) => write!(f, "invalid txid: {err}"), Self::Index(err) => write!(f, "invalid index: {err}"), } } } impl std::error::Error for ParseError {} impl FromStr for InscriptionId { type Err = ParseError; fn from_str(s: &str) -> Result { if let Some(char) = s.chars().find(|char| !char.is_ascii()) { return Err(ParseError::Character(char)); } const TXID_LEN: usize = 64;