pub(crate) fn fraction(bytes: &[u8], max_precision: usize) -> Result<i64, Error>
Expand description
Parses an i64
fractional number from the beginning to the end of the
given slice of ASCII digit characters.
The fraction’s maximum precision must be provided. The returned integer
will always be in units of 10^{max_precision}
. For example, to parse a
fractional amount of seconds with a maximum precision of nanoseconds, then
use max_precision=9
.
If any byte in the given slice is not [0-9]
, then this returns an error.
Similarly, if the fraction parsed does not fit into a i64
, then this
returns an error. Notably, this routine does not permit parsing a negative
integer. (We use i64
because everything in this crate uses signed
integers, and because a higher level routine might want to parse the sign
and then apply it to the result of this routine.)