-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
update documentation of tuple/unit structs #33250
Conversation
I made the "tuple structs are useless" editorializing a bit weaker and moved it to the end. Feel free to overrule me on that. I also added an example of how to unpack a tuple struct with dot notation, because it came up on IRC. `braced_empty_structs` is stable now, so I updated the example for unit-like structs to use that syntax. Should we show both ways? cc @ubsan r? @steveklabnik or @GuillameGomez
@@ -163,11 +163,48 @@ struct Point(i32, i32, i32); | |||
let black = Color(0, 0, 0); | |||
let origin = Point(0, 0, 0); | |||
``` | |||
|
|||
Here, `black` and `origin` are not equal, even though they contain the same | |||
values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence could be confusing even though I get what it is trying to say. Color(0, 0, 0)
and Color(0, 0, 0)
are also not "equal" in some sense because we didn't derive PartialEq
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should just say "are not the same type, even though they contain the same values".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent idea! Your second suggestion is just perfect. Could you replace the sentence please?
I'm of the opinion it should show both ways, or only |
That's the opposite of the advice you gave me on IRC :) The RFC doesn't say anything about this -- it says if you have I now think the book should show both ways, but maybe handwave over the type/value namespace thing (leave that to the reference). |
@durka: If the empty braces are stable then yes. Adding features in documentation would make the whole a lot more complicated. Let's wait for @steveklabnik's confirmation. |
`let`, just like regular tuples: | ||
|
||
```rust | ||
# struct Color(i32, i32, i32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the '#' at the beginning of the line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To hide the line from the documentation, while it's needed to make the example self-contained it's repetitive from the example above.
I am not sure what the preferred way should be, to be honest. |
I am generally pro this patch, but yeah, the conventions question is interesting. @aturon ? |
let integer_length = length.0; | ||
``` | ||
|
||
It's always possible to use a `struct` than a tuple struct, and can be clearer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/than/instead of/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops.
r=me @steveklabnik |
Any interest in committing to a convention here? |
Hmm, I'm of the opinion that |
@ubsan any reasoning behind that, or just aesthetics? |
To take a counter-position (I truly don't feel strongly): |
I do not want to block this PR on a conventions question we don't have a good way to answer. @durka can you update it with showing both forms, please? And then r=me after. |
Done. |
@bors: r+ rollup Thanks! :) |
📌 Commit 74e9629 has been approved by |
update documentation of tuple/unit structs I made the "tuple structs are useless" editorializing a bit weaker and moved it to the end. Feel free to overrule me on that. I also added an example of how to unpack a tuple struct with dot notation, because it came up on IRC. `braced_empty_structs` is stable now, so I updated the example for unit-like structs to use that syntax. Should we show both ways? cc @ubsan r? @steveklabnik or @GuillaumeGomez
update documentation of tuple/unit structs I made the "tuple structs are useless" editorializing a bit weaker and moved it to the end. Feel free to overrule me on that. I also added an example of how to unpack a tuple struct with dot notation, because it came up on IRC. `braced_empty_structs` is stable now, so I updated the example for unit-like structs to use that syntax. Should we show both ways? cc @ubsan r? @steveklabnik or @GuillaumeGomez
update documentation of tuple/unit structs I made the "tuple structs are useless" editorializing a bit weaker and moved it to the end. Feel free to overrule me on that. I also added an example of how to unpack a tuple struct with dot notation, because it came up on IRC. `braced_empty_structs` is stable now, so I updated the example for unit-like structs to use that syntax. Should we show both ways? cc @ubsan r? @steveklabnik or @GuillaumeGomez
I made the "tuple structs are useless" editorializing a bit weaker and moved it to the end. Feel free to overrule me on that.
I also added an example of how to unpack a tuple struct with dot notation, because it came up on IRC.
braced_empty_structs
is stable now, so I updated the example for unit-like structs to use that syntax. Should we show both ways?cc @ubsan
r? @steveklabnik or @GuillaumeGomez