Function btoi::btoi_radix
[−]
[src]
pub fn btoi_radix<I>(bytes: &[u8], radix: u8) -> Result<I, ParseIntegerError> where
I: FromPrimitive + Zero + CheckedAdd + CheckedSub + CheckedMul,
Converts a byte slice in a given base to an integer.
Like btou_radix
, but numbers may optionally start with a sign
(-
or +
).
Errors
Returns ParseIntegerError
for any of the following conditions:
bytes
has no digits- not all characters of
bytes
are0-9
,a-z
,A-Z
, exluding an optional leading sign - not all characters refer to digits in the given
radix
, exluding an optional leading sign - the number overflows or underflows
I
Panics
Panics if radix
is not in the range 2..=36
(or in the pathological
case that there is no representation of radix
in I
).
Examples
assert_eq!(Ok(10), btoi_radix(b"a", 16)); assert_eq!(Ok(10), btoi_radix(b"+a", 16)); assert_eq!(Ok(-42), btoi_radix(b"-101010", 2));