[][src]Function pir_8_emu::util::parse_with_prefix

pub fn parse_with_prefix<T: Num + PrimInt>(from: &str) -> Option<T>

Parse a number from the specified string, automatically detecting the base prefix.

Examples

assert_eq!(parse_with_prefix::<u16>("0x0420"), Some(0x0420));
assert_eq!(parse_with_prefix::<u16>("0o0420"), Some(0o0420));
assert_eq!(parse_with_prefix::<u16>("0B0101"), Some(0b0101));

assert_eq!(parse_with_prefix::<u16>("0b1010_0101"), Some(0b1010_0101));

assert_eq!(parse_with_prefix::<u16>("0"), Some(0));

assert_eq!(parse_with_prefix::<u16>("0x2OOM"), None);