pub fn btoi<I>(bytes: &[u8]) -> Result<I, ParseIntegerError>Expand description
Converts a byte slice to an integer.
Like btou, but numbers may optionally start with a sign (- or +).
§Errors
Returns ParseIntegerError for any of the following conditions:
byteshas no digits- not all characters of
bytesare0-9, excluding an optional leading sign - the number overflows
I(positively or negatively)
§Panics
Panics in the pathological case that there is no representation of 10
in I.
§Examples
assert_eq!(Ok(123), btoi(b"123"));
assert_eq!(Ok(123), btoi(b"+123"));
assert_eq!(Ok(-123), btoi(b"-123"));
assert!(btoi::<i16>(b"123456789").is_err()); // positive overflow
assert!(btoi::<u32>(b"-1").is_err()); // negative overflow
assert!(btoi::<i32>(b" 42").is_err()); // leading space