-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generics: Make enum variant syntax consistent with other types #2218
Comments
This is a sub-problem of other already accepted feature rust-lang/rust#26264. |
Both syntaxes could be allowed to fix the variant import issue (I don't see how type aliases address that). I agree it's confusing that |
@durka Variant imports can be done in a similar way that you'd import a generic type today, making the imports consistent too. (Basically, you don't import a variant directly, instead you achieve the same by importing the generic type and type aliasing it - just like every other type today). use std::option::Option;
type MyOption = Option<MyType>; |
Here is another, although a different side of this consistency problem: You can define type aliases to types in a way that "statically curries" the type parameters. For example, you can define You can't define Type aliases are for simplifying types. The same, of course could apply for functions, but they might have been lacking a sufficient demand for it. However, there is another implication that this kind of an extension would have: treating instantiations of generic functions as stand-alone items. This helps especially some macros, as the generic syntax might clobber them up, but "redefining" the generic as non-generic items prevents this problem. |
Any progress on that? Accept/Reject/...? |
I have a large number of dynamically dispatched structs that are not object safe, therefore I use a gigantic enum. To run code on this, I need to use macro's. It seems to me that being able to have a function be generic over enum variants would solve this use case in a much cleaner way. |
Accessing generics in Rust roughly revolves around the below syntax today:
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:
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 haveVariant(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.
The text was updated successfully, but these errors were encountered: