Skip to main content

parse_u64

Function parse_u64 

Source
pub fn parse_u64(digits: &[u8]) -> Result<u64, ParseError>
Expand description

Parses 1*DIGIT into a u64.

No sign, no whitespace, no trimming; leading zeros are allowed.

§Errors

ErrorKind::Empty for an empty input, ErrorKind::InvalidNumber at the first byte that is not a digit, ErrorKind::NumberOverflow at the digit that overflows.

§Examples

use parse_net::{num::parse_u64, ErrorKind};

assert_eq!(parse_u64(b"18446744073709551615")?, u64::MAX);
assert_eq!(parse_u64(b"18446744073709551616").unwrap_err().kind(), ErrorKind::NumberOverflow);
assert_eq!(parse_u64(b"+1").unwrap_err().kind(), ErrorKind::InvalidNumber);