I am reading Rust by Example book. In this example removing return in Err(e) => return Err(e) causes an error: expected `i32`, found enum `Result`` . Why is that?
What is the difference between Err(e) => return Err(e) and Err(e) => Err(e)?
Here is the code from the example:
use std::num::ParseIntError; fn main() -> Result<(), ParseIntError> { let number_str = "10"; let number = match number_str.parse::<i32>() { Ok(number) => number, Err(e) => return Err(e), }; println!("{}", number); Ok(()) }
matchis being bound tonumber. What could the type ofnumberbe? In your version, the result of the match could be either of typei32orResult, and the type ofnumbercan only be one or the other, chosen at compile time.