diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index 6c0c8a010143..3b9750a8d63b 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -131,6 +131,23 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer)
}
}
+/// For large structs, enums, unions, etc, determine whether to hide their fields
+fn should_hide_fields(n_fields: usize) -> bool {
+ // todo: figure out what this should be
+ n_fields > 5
+}
+
+fn toggle_open(w: &mut Buffer, text: &str)
+{
+ write!(w, "
", text);
+}
+
+fn toggle_close(w: &mut Buffer)
+{
+ w.write_str("
");
+}
+
+
fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) {
document(w, cx, item, None);
@@ -816,6 +833,10 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
w.write_str(" {}");
} else {
w.write_str(" {\n");
+ let toggle = should_hide_fields(e.variants.len());
+ if toggle {
+ toggle_open(w, "variants");
+ }
for v in &e.variants {
w.write_str(" ");
let name = v.name.as_ref().unwrap();
@@ -844,6 +865,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
if e.variants_stripped {
w.write_str(" // some variants omitted\n");
}
+ if toggle {
+ toggle_close(w);
+ }
w.write_str("}");
}
w.write_str("")
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 0abfe18a19f3..f112a113adcb 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -2703,6 +2703,10 @@ function hideThemeButtonState() {
}
});
}
+ } else if (hasClass(e, "type-contents-toggle")) {
+ let text = e.getAttribute("data-toggle-text");
+ let tog = createToggle(toggle, `Show ${text}`, null, "", true);
+ e.parentNode.insertBefore(tog, e);
}
if (e.parentNode.id === "main") {
var otherMessage = "";
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 585b7459bd71..3a171a1d6522 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -970,6 +970,10 @@ a.test-arrow:hover{
position: absolute;
left: -23px;
top: 0;
+
+ /* The click event for this is defined on the document,
+ so bubbling does not work. See https://github.com/rust-lang/rust/issues/83332 */
+ z-index: 10;
}
h3 > .collapse-toggle, h4 > .collapse-toggle {
@@ -1054,10 +1058,9 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
margin-top: 3px;
}
+/* for enum and struct fields */
.enum > .toggle-wrapper + .docblock, .struct > .toggle-wrapper + .docblock {
- margin-left: 30px;
- margin-bottom: 20px;
- margin-top: 5px;
+ margin-left: 0px;
}
.docblock > .section-header:first-child {
@@ -1069,10 +1072,6 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
left: -10px;
}
-.enum > .collapsed, .struct > .collapsed {
- margin-bottom: 25px;
-}
-
#main > .variant, #main > .structfield {
display: block;
}