Is using ? a language or library feature?

I am new to learning rust.
So far my understanding is that the Option is a library feature and most related featurs of Option are possible for other enums as well.

But how does the "?" syntax work for Option being None?
e.g.

let var = some_api()?

How is the ? syntax specific to a library enum?

1 Like

The ? operator corresponds to the Try trait. Unfortunately it isn't stable, so unless you're using a nightly compiler you can't currently implement it for your own types.

7 Likes

Got it, so it has nothing to do with specifics of Options
It just calls few methods from the Try trait and ends up implementing the current ? functionality that we know of

Thanks!

For more, you can read about it in RFC#3058: https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#the-try-trait.