diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-03-20 19:39:29 -0700 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2021-04-12 08:45:45 -0700 |
| commit | 173cbecc66ee1bbb54c039a00c3b75b4cdf7e277 (patch) | |
| tree | c7e9aabaf9aed47fb65a668a31c03b39aa051d7a /src/librustdoc/html/render | |
| parent | f146b9701df0e26dad61422089d3a7e9a49989c5 (diff) | |
| download | rust-173cbecc66ee1bbb54c039a00c3b75b4cdf7e277.tar.gz rust-173cbecc66ee1bbb54c039a00c3b75b4cdf7e277.zip | |
rustdoc: smartly hide associated items of traits if there are too many of them
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index b6e9a8e244a..8db78e7718d 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -443,10 +443,25 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra } else { // FIXME: we should be using a derived_id for the Anchors here w.write_str("{\n"); + let mut toggle = false; + + // If there are too many associated types, hide _everything_ + if should_hide_fields(types.len()) { + toggle = true; + toggle_open(w, "associated items"); + } for t in &types { render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait, cx); w.write_str(";\n"); } + // If there are too many associated constants, hide everything after them + // We also do this if the types + consts is large because otherwise we could + // render a bunch of types and _then_ a bunch of consts just because both were + // _just_ under the limit + if !toggle & should_hide_fields(types.len() + consts.len()) { + toggle = true; + toggle_open(w, "associated constants and methods"); + } if !types.is_empty() && !consts.is_empty() { w.write_str("\n"); } @@ -454,6 +469,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra render_assoc_item(w, t, AssocItemLink::Anchor(None), ItemType::Trait, cx); w.write_str(";\n"); } + if !toggle & should_hide_fields(required.len() + provided.len()) { + toggle = true; + toggle_open(w, "methods"); + } if !consts.is_empty() && !required.is_empty() { w.write_str("\n"); } @@ -484,6 +503,9 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra w.write_str("<div class=\"item-spacer\"></div>"); } } + if toggle { + toggle_close(w); + } w.write_str("}"); } w.write_str("</pre>") @@ -1284,9 +1306,7 @@ fn render_union( write!(w, " {{\n{}", tab); let count_fields = fields .iter() - .filter( - |f| if let clean::StructFieldItem(..) = *f.kind { true } else { false }, - ) + .filter(|f| if let clean::StructFieldItem(..) = *f.kind { true } else { false }) .count(); let toggle = should_hide_fields(count_fields); if toggle { @@ -1343,9 +1363,7 @@ fn render_struct( w.write_str(" {"); let count_fields = fields .iter() - .filter( - |f| if let clean::StructFieldItem(..) = *f.kind { true } else { false }, - ) + .filter(|f| if let clean::StructFieldItem(..) = *f.kind { true } else { false }) .count(); let has_visible_fields = count_fields > 0; let toggle = should_hide_fields(count_fields); |
