Core Intermediate
08 Error handling
Rust models absence and failure in the type system: return an Option for a maybe-missing char, then use ? to propagate parse errors.
Parse both strings as i32 and return their sum in add_str, using ? to propagate errors.
Hints
s.parse::<i32>()?unwraps on success or returns the error early; finish withOk(...).
Reveal solution
fn add_str(a: &str, b: &str) -> Result<i32, std::num::ParseIntError> {
let x = a.parse::<i32>()?;
let y = b.parse::<i32>()?;
Ok(x + y)
}