btoi

Function btou_radix

Source
pub fn btou_radix<I>(bytes: &[u8], radix: u32) -> Result<I, ParseIntegerError>
Expand description

Converts a byte slice in a given base to an integer. Signs are not allowed.

§Errors

Returns ParseIntegerError for any of the following conditions:

  • bytes is empty
  • not all characters of bytes are 0-9, a-z or A-Z
  • not all characters refer to digits in the given radix
  • the number overflows 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(255), btou_radix(b"ff", 16));
assert_eq!(Ok(42), btou_radix(b"101010", 2));