Medium
Propagating a parse error through nested ? operators
What does this program print?
main.rs
use std::num::ParseIntError;
fn parse_and_double(s: &str) -> Result<i32, ParseIntError> {
let n: i32 = s.parse()?;
Ok(n * 2)
}
fn process(a: &str, b: &str) -> Result<i32, ParseIntError> {
let x = parse_and_double(a)?;
let y = parse_and_double(b)?;
Ok(x + y)
}
fn main() {
match process("3", "abc") {
Ok(v) => println!("Ok({})", v),
Err(e) => println!("Err({})", e),
}
}38 of 53 in Rust