Why can I not use the `?` operator here?

37 points camilo16

I decided to give rust a try for the very first time, I am trying to write a program that parses gltf files and applies a linear transformation to all data (because I need this tool).

To that effect I wrote this:

use gltf::Gltf;

fn main() {
    let gltf = Gltf::open("examples/Box.gltf")?;
    for scene in gltf.scenes() {
        for node in scene.nodes() {
            println!(
                "Node #{} has {} children",
                node.index(),
                node.children().count(),
            );
        }
    }
}

Which is basically just a copy pasted version of what the crate's documentation says:
https://docs.rs/gltf/latest/gltf/

But I get this error when i try to run the code:

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
 --> src/main.rs:4:47
  |
3 | / fn main() {
4 | |     let gltf = Gltf::open("examples/Box.gltf")?;
  | |                                               ^ cannot use the `?` operator in a function that returns `()`
5 | |
6 | |     // println!(gltf);
7 | | }
  | |_- this function should return `Result` or `Option` to accept `?`
  |
  = help: the trait `FromResidual<Result<Infallible, gltf::Error>>` is not implemented for `()`

All I did was copy paste the base example, what am I messing up?