Auto merge of #37728 - QuietMisdreavus:rustdoc-enum-struct, r=GuillaumeGomez
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](https://github.com/rust-lang/rust/issues/37500#issuecomment-260069269), 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
This commit is contained in:
@@ -2488,8 +2488,13 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
if let clean::VariantItem(Variant {
|
||||
kind: VariantKind::Struct(ref s)
|
||||
}) = variant.inner {
|
||||
write!(w, "<h3 class='fields'>Fields</h3>\n
|
||||
<table>")?;
|
||||
let variant_id = derive_id(format!("{}.{}.fields",
|
||||
ItemType::Variant,
|
||||
variant.name.as_ref().unwrap()));
|
||||
write!(w, "<span class='docblock autohide sub-variant' id='{id}'>",
|
||||
id = variant_id)?;
|
||||
write!(w, "<h3 class='fields'>Fields of <code>{name}</code></h3>\n
|
||||
<table>", name = variant.name.as_ref().unwrap())?;
|
||||
for field in &s.fields {
|
||||
use clean::StructFieldItem;
|
||||
if let StructFieldItem(ref ty) = field.inner {
|
||||
@@ -2513,7 +2518,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
write!(w, "</td></tr>")?;
|
||||
}
|
||||
}
|
||||
write!(w, "</table>")?;
|
||||
write!(w, "</table></span>")?;
|
||||
}
|
||||
render_stability_since(w, variant, it)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user