Protocol std::builtins::internal::IntegerParsable
protocol IntegerParsable<Self> { ... }
Self: Integer
Mixin for parsing integers from strings.
Provided methods
-
Parses the integer from a base-10 string.
If the string does not represent a valid integer,
Option::none()
is returned.Example
assert_eq!(i32::parse("10"), Option::some(10)); assert_eq!(i32::parse("foo"), Option::none());
Run this example -
Parses the integer from a string in a given base.
If the string does not represent a valid integer in the given base,
Option::none()
is returned.Example
assert_eq!(i32::parse_with_radix("10", 2), Option::some(2)); assert_eq!(u64::parse_with_radix("deadbeef", 16), Option::some(0xdeadbeefu64)); assert_eq!(i32::parse_with_radix("foo", 10), Option::none());
Run this example