Description
Accessing generics in Rust roughly revolves around the below syntax today:
Item | Syntax |
---|---|
Type | T::<VARIANT>::Item |
Method Calls | Function::<VARIANT>() |
Enum | T::Item::<VARIANT> |
While the first are second are fairly consistent, the enum
one is weird and almost has an opposite syntax. The reasons mostly seem to be just historical for the inconsistency.
To illustrate it with an example:
let x = None::<i32>; // OK
let x = Option::<i32>::None; // Compiler error. (But this is the type syntax)
I think it would be nicer to allow a more consistent syntax, that allow enum to be work with the Type
syntax as above.
Potential side-effects:
While bringing this up in the IRC, one of the nice folks pointed this very useful feature out - with the existing syntax, you can do use self::Enum::Variant;
and then have Variant(foo)
in the code. But this can easily be achieved with type aliasing, with the above syntax - making it even more consistent with other types.
While the existing syntax may or may not be deprecated at a later stage - I think adding a consistent syntax would be very useful.