Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRusterror handling thiserror anyhowSingle-choice MCQ

On the error path, what value does parse("xx") return, and what made the conversion happen?

use std::fmt; #[derive(Debug)] struct MyErr(String); impl fmt::Display for MyErr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } } impl std::error::Error for MyErr {} impl From<std::num::ParseIntError> for MyErr { fn from(e: std::num::ParseIntError) -> Self { MyErr(format!("parse: {e}")) } } fn parse(s: &str) -> Result<i32, MyErr> { let n: i32 = s.parse()?; Ok(n * 2) } fn main() { println!("{:?}", parse("xx")); }