gix_utils::btoi

Function to_unsigned_with_radix

source
pub fn to_unsigned_with_radix<I: MinNumTraits>(
    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), to_unsigned_with_radix(b"ff", 16));
assert_eq!(Ok(42), to_unsigned_with_radix(b"101010", 2));