Function btoi::btou_saturating
[−]
[src]
pub fn btou_saturating<I>(bytes: &[u8]) -> Result<I, ParseIntegerError> where
I: FromPrimitive + Zero + CheckedMul + Saturating + Bounded,
Converts a byte slice 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
Panics
Panics in the pathological case that there is no representation of 10
in I
.
Examples
assert_eq!(Ok(65535), btou_saturating::<u16>(b"65535")); assert_eq!(Ok(65535), btou_saturating::<u16>(b"65536")); // u16 saturated assert_eq!(Ok(65535), btou_saturating::<u16>(b"65537")); // u16 saturated