1pub(crate) trait Integer: Sized {
5 const MAX_NUM_DIGITS: u8;
7 const ZERO: Self;
9
10 fn push_digit(self, digit: u8) -> Self;
14
15 fn checked_push_digit(self, digit: u8) -> Option<Self>;
19}
20
21macro_rules! impl_parse_bytes {
23 ($($t:ty)*) => ($(
24 impl Integer for $t {
25 const MAX_NUM_DIGITS: u8 = match Self::MAX.checked_ilog10() {
26 Some(digits) => digits as u8 + 1,
27 None => 1,
28 };
29
30 const ZERO: Self = 0;
31
32 #[allow(trivial_numeric_casts, reason = "macro-generated code")]
33 #[inline]
34 fn push_digit(self, digit: u8) -> Self {
35 self * 10 + digit as Self
36 }
37
38 #[allow(trivial_numeric_casts, reason = "macro-generated code")]
39 #[inline]
40 fn checked_push_digit(self, digit: u8) -> Option<Self> {
41 self.checked_mul(10)?.checked_add(digit as Self)
42 }
43 }
44 )*)
45}
46impl_parse_bytes! { u8 u16 u32 u128 }