-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Misleading docs for an enum with struct variants #37500
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
Comments
A tricky one. The problem just gets bigger if it has more "sub-levels". The output shouldn't be based on indentation therefore. I'm more in favor for bigger margin between the struct fields and the other variants. Also, it would be nice to replace "Fields" by something like "Fields of |
I just took a moment to try out a few variations that might work for this. They all assume that the "Fields" header will include the name of the variant being described, but beyond that take a couple different directions of how it gets laid out. Option 1: Extra margin under the list of struct fieldsThis is the simplest option, as all it does is slap some extra padding underneath the listing of struct fields via CSS. It provides a visible separation from the list of struct fields and the next variant in the listing. Option 2: Print struct variant fields after the list of variantsThis one's my personal favorite, as it provides a clean separation between the variant listing and the struct-field listing, without depending on more subtle style changes. On the other hand, it has the potential to put too much distance between a variant and its fields if an enum is huge enough. That could be mitigated by adding links and anchors between these sections. Option 3: Either of the above, but with borders around the field listingThe list of struct fields is printed in a Thoughts? Opinions? |
My favorite is the first, but the result isn't good enough yet. It might be interesting to be able to hide by default the sub-type content and add a "show |
This is probably too complicated, but Option 2 could have the following tweaks as well: for every subfield named the same, group them together (they're usually related anyways) and then list the variants it is a part of. enum Animal {
Cat { name: String, lives: u8, },
Dog { name: String, breed: String, },
} could render the |
@GuillaumeGomez I've changed my mind, this looks a lot nicer. Option 4: Wrap struct variant field listings in an auto-hidden blockWhen you initially load the page, there's a line under variants with struct fields letting you know you can click to expand the listing. If you click to expand, the header and table unfold into a nicely-indented listing. The indentation and table borders fell into place with its presence in this folding block, and I really like how it looks. If you want to take a look in your own browser and screen size, I've got this version hosted on my server. |
…meGomez rustdoc: fold fields for enum struct variants into a docblock Per discussion in #37500, this PR updates the enum rendering code to wrap variants with named struct fields in a `docblock` span that is hidden automatically upon load of the page. This gives struct variant fields a clean separation from other enum variants, giving a boost to the readability of such documentation. Preview output is available [on the issue page](#37500 (comment)), but for the sake of completeness I'll include the images here again.  When you initially load the page, there's a line under variants with struct fields letting you know you can click to expand the listing.  If you click to expand, the header and table unfold into a nicely-indented listing. If you want to take a look in your own browser and screen size, [I've got this version hosted on my server](https://shiva.icesoldier.me/doctest/doctest/enum.OldTopicRemoval.html). Fixes #37500 r? @GuillaumeGomez
…meGomez rustdoc: fold fields for enum struct variants into a docblock Per discussion in #37500, this PR updates the enum rendering code to wrap variants with named struct fields in a `docblock` span that is hidden automatically upon load of the page. This gives struct variant fields a clean separation from other enum variants, giving a boost to the readability of such documentation. Preview output is available [on the issue page](rust-lang/rust#37500 (comment)), but for the sake of completeness I'll include the images here again.  When you initially load the page, there's a line under variants with struct fields letting you know you can click to expand the listing.  If you click to expand, the header and table unfold into a nicely-indented listing. If you want to take a look in your own browser and screen size, [I've got this version hosted on my server](https://shiva.icesoldier.me/doctest/doctest/enum.OldTopicRemoval.html). Fixes #37500 r? @GuillaumeGomez
Given this structure:
I'm seeing docs rendered as:
Which makes it look like
Removed
is more closely related to the fields ofObsoleted
rather than on the same level. It'd be nice if the fields for theObsoleted
variant fields were either indented somehow or collapsed with the description.The text was updated successfully, but these errors were encountered: