The ? operator is used to unwrap a Result and either show the error, if there is one, or the value if it was successful. You can write the same thing out in long form, but since it was such a common operation this shorthand was introduced into the language.
You can read more about the operator in the docs, for example here: doc.rust-lang.org/rust-by-example/std/result/ques…
Brett Rowberry
Husband, dad, manager, functional programmer, and DIYer
Hashnode prompted me to make this comment. Very accessible! It wasn't clear to me why
?is needed here:fn main() { let result = divide(10, 2)?; println!("The result is {}", result); }What happens without it?