summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_json/src/lexical/digit.rs
blob: 882aa9eef2866eddc25a9575c36121bd8907a0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Adapted from https://github.com/Alexhuszagh/rust-lexical.

//! Helpers to convert and add digits from characters.

// Convert u8 to digit.
#[inline]
pub(crate) fn to_digit(c: u8) -> Option<u32> {
    (c as char).to_digit(10)
}

// Add digit to mantissa.
#[inline]
pub(crate) fn add_digit(value: u64, digit: u32) -> Option<u64> {
    value.checked_mul(10)?.checked_add(digit as u64)
}