What does the question mark operator (?) do in Rust and how does it work with errors?
Hello everyone! I'm new to Rust and trying to understand error handling. I often see a strange question mark operator — `?` — in other people's code. For example, this code:
```rust
use std::fs::File;
use std::io::Read;
fn read_file(path: &str) -> Result {
let mut file = File::open(path)?;
let mut content = String::new();
file.read_to_string(&mut content)?;
Ok(content)
}
```
I understand that `File::open` returns a `Result`, but what does this `?` at the end of the line do? Without it, the compiler complains that I'm not handling the `Result`. But if I add `?`, the code works.
I tried reading the documentation, but it's written in a complicated way. Can you explain in simple terms: what is this magic question mark? Is it somehow related to `unwrap()` or `match`? Why does the function return