pub fn btou_saturating_radix<I>(
bytes: &[u8],
radix: u32,
) -> Result<I, ParseIntegerError>
Expand description
Converts a byte slice in a given base to the closest possible integer. Signs are not allowed.
§Errors
Returns ParseIntegerError
for any of the following conditions:
bytes
is empty- not all characters of
bytes
are0-9
,a-z
,A-Z
- not all characters refer to digits in the given
radix
§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_saturating_radix::<u8>(b"00ff", 16));
assert_eq!(Ok(255), btou_saturating_radix::<u8>(b"0100", 16)); // u8 saturated
assert_eq!(Ok(255), btou_saturating_radix::<u8>(b"0101", 16)); // u8 saturated