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
src/doc/book/structs.md
Outdated
| ``` | ||
|
|
||
| Here, `black` and `origin` are not equal, even though they contain the same | ||
| values. |
There was a problem hiding this comment.
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.
Maybe it should just say "are not the same type, even though they contain the same values".
There was a problem hiding this comment.
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.
Why the '#' at the beginning of the line?
There was a problem hiding this comment.
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 ? |
src/doc/book/structs.md
Outdated
| let integer_length = length.0; | ||
| ``` | ||
|
|
||
| It's always possible to use a `struct` than a tuple struct, and can be clearer. |
|
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_structsis 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