Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Unwrap

This code uses .unwrap() on a parse that will fail, causing a crash! Fix it by using match instead so it handles the error gracefully.

Fix the code so it prints:

text
Could not parse "hello" as a number

Hint: Replace .unwrap() with a match that handles both Ok and Err.

rust
fn main() {
let input = "hello";
let number: i32 = input.parse().unwrap();
println!("Got: {}", number);
}