where D: Deserializer<'de>, { Ok(DeserializeFromStr::deserialize(deserializer)?.0) } } impl FromStr for SatPoint { type Err = Error; fn from_str(s: &str) -> Result { let (outpoint, offset) = s .rsplit_once(':') .ok_or_else(|| anyhow!("invalid satpoint: {s}"))?; Ok(SatPoint { outpoint: outpoint.parse()?, offset: offset.parse()?, }) } } #[cfg(test)] mod tests { use super::*; #[test] fn from_str_ok() { assert_eq!( "1111111111111111111111111111111111111111111111111111111111111111:1:1" .parse::() .unwrap(), SatPoint { outpoint: "1111111111111111111111111111111111111111111111111111111111111111:1" .parse() .unwrap(), offset: 1, } ); } #[test] fn from_str_err() { "abc".parse::().unwrap_err(); "abc:xyz".parse::().unwrap_err(); "1111111111111111111111111111111111111111111111111111111111111111:1" .parse::()