spectec_ast_decode/
u64.rs1fn parse_u64_str(s: &str) -> Result<u64, std::num::ParseIntError> {
2 if let Some(stripped) = s.strip_prefix("0x") {
3 u64::from_str_radix(stripped, 16)
4 } else {
5 s.parse::<u64>()
6 }
7}
8
9impl crate::Decode for u64 {
10 fn decode<'a, I: Iterator<Item = &'a sexpr_parse::SExprItem>>(
11 items: &mut std::iter::Peekable<I>,
12 ) -> crate::Result<Self> {
13 match items.next() {
14 Some(sexpr_parse::SExprItem::Atom(t)) => {
15 parse_u64_str(t).map_err(crate::Error::parse_int_err::<Self>)
16 }
17 Some(item) => Err(crate::Error::cannot_decode_sexpr::<Self>(item)),
18 None => Err(crate::Error::required_missing_sexpr::<Self>()),
19 }
20 }
21}