Don't you think this Option::<i32>::Some(32) syntax is a little bit inconsistant?

You can do both of the following:

let some_number=Option::<i32>::Some(32);
let absent_number : Option<i32> = None;

but don't you feel the syntax is more consistent if you can write it in this way:

let some_number=Option<i32>::Some(32);


That could be interpreted as:

let some_number = (Option < i32) > ::Some(32);

Although I'm not sure if ::Some(32) is valid, it would be pretty late to go back and reparse the first part, not to mention that some other expression could be valid, thus creating further inconsistency.

Mandatory link:

Finally, if you want consistency you can do this:

let absent_number: Option::<i32> = None;

:rofl:Thanks, your suggestion really works.
If you cannot make them more beautiful, you make them uglier. Nice :star_struck:

For the record, C++ has no turbofish equivalent to disambiguate template parameters from comparison operators, and even though it kind of works, it makes the already absurdly complicated parsing even more vexing – and you still need to disambiguate in certain situations with either the template or typename keyword. Rust is, at least, consistent.

It's a valid invocation of a function/tuple struct constructor that's named Some and exists in the crate root.


It's 100% valid; a leading double-colon qualifies the top-level namespace.

(But even if it weren't, this sort of ambiguity would still be bad.)

I'm pretty sure the accusatory "don't you think this is kind of stupid"-like pharsing, combined with a suggestive emoji, is not the appropriate way to ask a question. A bit more respect for the language designers, please. Rust is an exceptionally well-designed language, and things aren't ad-hoc or without a reason. This, rather than "oh it's a design/compiler bug", should be your default assumption.


I'd prefer

let some_number=Some(32_i32);

which require less code to wrote.


FWIW, I didn't take OP's tone and emoji use as being critical the language (on the contrary, I read ":joy:" as an attempt of lightening the question's tone), but that's the trouble with emoji, many of them are ambiguous and should be avoided outside very casual conversations.


That is true, there is none any disrespect here. Thanks.


More alternatives……

    let some_number = <Option<i32>>::Some(32);
    let some_number = Option::Some::<i32>(32);
    // and, since `Option::Some` is in the prelude:
    let some_number = Some::<i32>(32);



Well, if you want to, you can write it like this:

let some_number = <Option<i32>>::Some(32);

(This is "UFCS", though not in the form usually seen where it includes an as Trait.)


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.