What's None::<usize> mean?

In match - Rust (rust-lang.org), there is "None::<usize>", what's that mean? Thanks!

let opt = Option::None::<usize>;
let x = match opt {
    Some(int) => int,
    None => 10,
assert_eq!(x, 10);

It's the same as let opt: Option<usize> = None;

The syntax is called turbofish. You can read about it more here


In addition to what @zynaxsoft wrote, one thing I like about turbofish syntax is that it, at least to me, somewhat more clearly illustrates that a None, when used with an Option<T>, is tied to the T. I.e. there isn't a single None, it's always a part of another type. (This is useful to know because one sometimes ends up in a situation where the compiler tells you it doesn't know what None is meant, and one needs to annotate it with the specific type).


It means the same thing as <Option<usize>>::None, but is how the type can be explicitly specified when the variant has already been imported.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.