const MIN_LEN: usize = TXID_LEN + 2; if s.len() < MIN_LEN { return Err(ParseError::Length(s.len())); } let txid = &s[..TXID_LEN]; let separator = s.chars().nth(TXID_LEN).unwrap(); if separator != 'i' { return Err(ParseError::Separator(separator)); } let vout = &s[TXID_LEN + 1..]; Ok(Self { txid: txid.parse().map_err(ParseError::Txid)?, index: vout.parse().map_err(ParseError::Index)?, }) } } #[cfg(test)] mod tests { use super::*; #[test] fn display() { assert_eq!( inscription_id(1).to_string(), "1111111111111111111111111111111111111111111111111111111111111111i1", ); assert_eq!( InscriptionId { txid: txid(1), index: 0, } .to_string(), "1111111111111111111111111111111111111111111111111111111111111111i0", ); assert_eq!( InscriptionId { txid: txid(1), index: 0xFFFFFFFF, } .to_string(), "1111111111111111111111111111111111111111111111111111111111111111i4294967295",