-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Rename tuple structs to something else #7288
Comments
I'm strongly opposed to adding a tuple keyword. I think that an alternative might be to use the enum keyword instead. I feel that it would be very sensible to have what is now a tuple struct be a single case enum. |
@sstewartgallus what is a single case enum? Tuple structs are like I agree that adding a keyword is bad but there are no suitable ones already in the grammar... and the current situation is pretty inexplicable. Most of the badness comes from abusing the term Maybe it's just something we'll have to live with, though. |
I might be the only one, but I really like the current system, and can't think of any way I would improve on it. Data can use either named syntax (record-like) or unnamed syntax (tuple-like). Structs are single-variant, enums can have multiple. Built-in tuples use the unnamed syntax and also leave off the type name. Structs using tuple-like syntax with a single field just happen to be perfect for the (One way you could simplify it is by collapsing All of that said, as the way to talk about them I'm not attached to "tuple struct" even a little bit, and "named tuple" doesn't sound any worse.
The point isn't to give it a new name, it's to give it a new type, so that the compiler yells at you if you mix them up. |
@glehel I like the current system too. "tuple struct" is the only thing that annoys me. I might be the only one, though. As for newtype, I thought typedefs did that, but I guess not, doing some tests. Nor would it make sense, really. Typedefs are most often used to have a shorter name for something, which wouldn't work if it were a newtype. |
@cmr By single case enum I meant anything like |
@sstewartgallus I'd be ok with that. I think it's better than using |
FWIW that's very similar to the old syntax: You can currently write four things: (1) These have a certain logic to them: 2 * 2 = 4 possibilities. You're proposing a fifth: (5) Which of the existing four would you remove? Presumably (2); also (4)? (1)? Would you also add: (6) which follows from the same syntactic-sugar-for-single-case-enums logic? At that point there's no reason to keep the |
@glehel the more I think about it (your examples were particularly enlightening), the more I think My biggest beef is the name. The only other thing I can really come up with, though, is unstructured struct, which is longer and also rates fairly high on the WTF scale. Maybe there isn't a better name. |
@glehel I feel that cases 6, 2, and 3 are not useful, and that the fifth case is useful. |
Closing due to lack of consensus. |
Fix use_self FPs on type params changelog: Fix [`use_self`] false positives on type parameters Fixes rust-lang#4140 Fixes rust-lang#7139
"tuple struct" is a pretty terrible name. I propose "named tuple". This would also change the syntax from
struct Foo(....)
to
tuple Foo(...)
.Only reason is because you can't have impls or traits on typedefs. If you could, this feature could be reduced to
type Foo = (....)
, which would be ideal I think.The text was updated successfully, but these errors were encountered: