The only way to introspect reason of .parse failure is to compare to error messages returned by description or use the following code snippet:
let overflow = "1231123123123123".parse::<u32>().err().unwrap();
let underflow = "-1231123123123123".parse::<i32>().err().unwrap();
match "999999999999".parse::<u32>() {
Ok(n) => println!("{}", n),
Err(ref e) if *e == overflow => println!("Overflow"),
Err(ref e) if *e == underflow => println!("Underflow"),
_ => panic!("wow, no introspection, very convenience")
}
The only way to introspect reason of
.parsefailure is to compare to error messages returned by description or use the following code snippet: