Beginner Rust fan - I am getting a panic for either one of these.
I expected it from the first part, but not the second.
What am I missing?
fn main() {
//let age = "4a";
//let age2: i32 = age.trim().parse().unwrap();
//println!("{:?}", age2);
let age = "4a";
let age2: i32 = age.trim().parse().expect("What was this?");
println!("{:?}", age2);
}
From
expect()'s documentation:The only difference to
unwrap()is the customized error message.See also: When should we use unwrap vs expect in Rust.