I always thought that "?" operator simply inserts a match evaluation against two arms of a function call but run into this example in the rustlings error handling error5.rs file that seems to suggest that it also does additional evaluation and seems to be able to create a box if necessary.
Is there docs that properly explain what "?" operator does besides simply adding dummy Result arms eval?
DOES NOT WORK
fn main() -> Result<(), Box<dyn std::error::Error>> {
let me = "blah";
if me.len() > 2 {
return Err("Invalid len"); // <---- NO ?
}
Ok(())
}
WORKS
fn main() -> Result<(), Box<dyn std::error::Error>> {
let me = "blah";
if me.len() > 2 {
return Err("Invalid len")?;
}
Ok(())
}