@@ -11,8 +11,8 @@ use rustc_span::symbol::{kw, sym, Symbol};
11
11
12
12
use super :: {
13
13
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, render_assoc_item,
14
- render_assoc_items, render_attributes , render_impl , render_stability_since_raw , spotlight_decl ,
15
- write_srclink, AssocItemLink , Context ,
14
+ render_assoc_items, render_attributes_in_code , render_attributes_in_pre , render_impl ,
15
+ render_stability_since_raw , spotlight_decl , write_srclink, AssocItemLink , Context ,
16
16
} ;
17
17
use crate :: clean:: { self , GetDefId } ;
18
18
use crate :: formats:: cache:: Cache ;
@@ -137,11 +137,15 @@ fn should_hide_fields(n_fields: usize) -> bool {
137
137
}
138
138
139
139
fn toggle_open ( w : & mut Buffer , text : & str ) {
140
- write ! ( w, "<div class=\" docblock type-contents-toggle\" data-toggle-text=\" {}\" >" , text) ;
140
+ write ! (
141
+ w,
142
+ "<details class=\" type-contents-toggle\" ><summary class=\" hideme\" ><span>Show {}</span></summary>" ,
143
+ text
144
+ ) ;
141
145
}
142
146
143
147
fn toggle_close ( w : & mut Buffer ) {
144
- w. write_str ( "</div >" ) ;
148
+ w. write_str ( "</details >" ) ;
145
149
}
146
150
147
151
fn item_module ( w : & mut Buffer , cx : & Context < ' _ > , item : & clean:: Item , items : & [ clean:: Item ] ) {
@@ -390,7 +394,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
390
394
)
391
395
. len ( ) ;
392
396
w. write_str ( "<pre class=\" rust fn\" >" ) ;
393
- render_attributes ( w, it, false ) ;
397
+ render_attributes_in_pre ( w, it, "" ) ;
394
398
write ! (
395
399
w,
396
400
"{vis}{constness}{asyncness}{unsafety}{abi}fn \
@@ -421,7 +425,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
421
425
// Output the trait definition
422
426
wrap_into_docblock ( w, |w| {
423
427
w. write_str ( "<pre class=\" rust trait\" >" ) ;
424
- render_attributes ( w, it, true ) ;
428
+ render_attributes_in_pre ( w, it, "" ) ;
425
429
write ! (
426
430
w,
427
431
"{}{}{}trait {}{}{}" ,
@@ -731,7 +735,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
731
735
732
736
fn item_trait_alias ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: TraitAlias ) {
733
737
w. write_str ( "<pre class=\" rust trait-alias\" >" ) ;
734
- render_attributes ( w, it, false ) ;
738
+ render_attributes_in_pre ( w, it, "" ) ;
735
739
write ! (
736
740
w,
737
741
"trait {}{}{} = {};</pre>" ,
@@ -752,7 +756,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea
752
756
753
757
fn item_opaque_ty ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: OpaqueTy ) {
754
758
w. write_str ( "<pre class=\" rust opaque\" >" ) ;
755
- render_attributes ( w, it, false ) ;
759
+ render_attributes_in_pre ( w, it, "" ) ;
756
760
write ! (
757
761
w,
758
762
"type {}{}{where_clause} = impl {bounds};</pre>" ,
@@ -774,7 +778,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean:
774
778
775
779
fn item_typedef ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , t : & clean:: Typedef ) {
776
780
w. write_str ( "<pre class=\" rust typedef\" >" ) ;
777
- render_attributes ( w, it, false ) ;
781
+ render_attributes_in_pre ( w, it, "" ) ;
778
782
write ! (
779
783
w,
780
784
"type {}{}{where_clause} = {type_};</pre>" ,
@@ -797,7 +801,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
797
801
fn item_union ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Union ) {
798
802
wrap_into_docblock ( w, |w| {
799
803
w. write_str ( "<pre class=\" rust union\" >" ) ;
800
- render_attributes ( w, it, true ) ;
804
+ render_attributes_in_pre ( w, it, "" ) ;
801
805
render_union ( w, it, Some ( & s. generics ) , & s. fields , "" , true , cx) ;
802
806
w. write_str ( "</pre>" )
803
807
} ) ;
@@ -843,7 +847,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
843
847
fn item_enum ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , e : & clean:: Enum ) {
844
848
wrap_into_docblock ( w, |w| {
845
849
w. write_str ( "<pre class=\" rust enum\" >" ) ;
846
- render_attributes ( w, it, true ) ;
850
+ render_attributes_in_pre ( w, it, "" ) ;
847
851
write ! (
848
852
w,
849
853
"{}enum {}{}{}" ,
@@ -1023,7 +1027,7 @@ fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
1023
1027
1024
1028
fn item_constant ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , c : & clean:: Constant ) {
1025
1029
w. write_str ( "<pre class=\" rust const\" >" ) ;
1026
- render_attributes ( w, it, false ) ;
1030
+ render_attributes_in_code ( w, it) ;
1027
1031
1028
1032
write ! (
1029
1033
w,
@@ -1059,7 +1063,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
1059
1063
fn item_struct ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Struct ) {
1060
1064
wrap_into_docblock ( w, |w| {
1061
1065
w. write_str ( "<pre class=\" rust struct\" >" ) ;
1062
- render_attributes ( w, it, true ) ;
1066
+ render_attributes_in_code ( w, it) ;
1063
1067
render_struct ( w, it, Some ( & s. generics ) , s. struct_type , & s. fields , "" , true , cx) ;
1064
1068
w. write_str ( "</pre>" )
1065
1069
} ) ;
@@ -1108,7 +1112,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1108
1112
1109
1113
fn item_static ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item , s : & clean:: Static ) {
1110
1114
w. write_str ( "<pre class=\" rust static\" >" ) ;
1111
- render_attributes ( w, it, false ) ;
1115
+ render_attributes_in_code ( w, it) ;
1112
1116
write ! (
1113
1117
w,
1114
1118
"{vis}static {mutability}{name}: {typ}</pre>" ,
@@ -1122,7 +1126,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
1122
1126
1123
1127
fn item_foreign_type ( w : & mut Buffer , cx : & Context < ' _ > , it : & clean:: Item ) {
1124
1128
w. write_str ( "<pre class=\" rust foreigntype\" >extern {\n " ) ;
1125
- render_attributes ( w, it, false ) ;
1129
+ render_attributes_in_code ( w, it) ;
1126
1130
write ! (
1127
1131
w,
1128
1132
" {}type {};\n }}</pre>" ,
@@ -1295,10 +1299,8 @@ fn render_union(
1295
1299
}
1296
1300
1297
1301
write ! ( w, " {{\n {}" , tab) ;
1298
- let count_fields = fields
1299
- . iter ( )
1300
- . filter ( |f| matches ! ( clean:: StructFieldItem ( ..) , * f. kind) )
1301
- . count ( ) ;
1302
+ let count_fields =
1303
+ fields. iter ( ) . filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
1302
1304
let toggle = should_hide_fields ( count_fields) ;
1303
1305
if toggle {
1304
1306
toggle_open ( w, "fields" ) ;
@@ -1356,10 +1358,8 @@ fn render_struct(
1356
1358
)
1357
1359
}
1358
1360
w. write_str ( " {" ) ;
1359
- let count_fields = fields
1360
- . iter ( )
1361
- . filter ( |f| matches ! ( clean:: StructFieldItem ( ..) = * f. kind) )
1362
- . count ( ) ;
1361
+ let count_fields =
1362
+ fields. iter ( ) . filter ( |f| matches ! ( * f. kind, clean:: StructFieldItem ( ..) ) ) . count ( ) ;
1363
1363
let has_visible_fields = count_fields > 0 ;
1364
1364
let toggle = should_hide_fields ( count_fields) ;
1365
1365
if toggle {
0 commit comments