1 | // Adapted from https://github.com/Alexhuszagh/rust-lexical. |
---|---|
2 | |
3 | //! Helpers to convert and add digits from characters. |
4 | |
5 | // Convert u8 to digit. |
6 | #[inline] |
7 | pub(crate) fn to_digit(c: u8) -> Option<u32> { |
8 | (c as char).to_digit(10) |
9 | } |
10 | |
11 | // Add digit to mantissa. |
12 | #[inline] |
13 | pub(crate) fn add_digit(value: u64, digit: u32) -> Option<u64> { |
14 | match value.checked_mul(10) { |
15 | None => None, |
16 | Some(n) => n.checked_add(digit as u64), |
17 | } |
18 | } |
19 |