@@ -613,7 +613,7 @@ fn short_item_info(
613
613
614
614
// Render the list of items inside one of the sections "Trait Implementations",
615
615
// "Auto Trait Implementations," "Blanket Trait Implementations" (on struct/enum pages).
616
- fn render_impls (
616
+ pub ( crate ) fn render_impls (
617
617
cx : & mut Context < ' _ > ,
618
618
w : & mut Buffer ,
619
619
impls : & [ & & Impl ] ,
@@ -1025,6 +1025,47 @@ impl<'a> AssocItemLink<'a> {
1025
1025
}
1026
1026
}
1027
1027
1028
+ fn write_impl_section_heading ( w : & mut Buffer , title : & str , id : & str ) {
1029
+ write ! (
1030
+ w,
1031
+ "<h2 id=\" {id}\" class=\" small-section-header\" >\
1032
+ {title}\
1033
+ <a href=\" #{id}\" class=\" anchor\" ></a>\
1034
+ </h2>"
1035
+ ) ;
1036
+ }
1037
+
1038
+ pub ( crate ) fn render_all_impls (
1039
+ w : & mut Buffer ,
1040
+ cx : & mut Context < ' _ > ,
1041
+ containing_item : & clean:: Item ,
1042
+ concrete : & [ & & Impl ] ,
1043
+ synthetic : & [ & & Impl ] ,
1044
+ blanket_impl : & [ & & Impl ] ,
1045
+ ) {
1046
+ let mut impls = Buffer :: empty_from ( w) ;
1047
+ render_impls ( cx, & mut impls, concrete, containing_item, true ) ;
1048
+ let impls = impls. into_inner ( ) ;
1049
+ if !impls. is_empty ( ) {
1050
+ write_impl_section_heading ( w, "Trait Implementations" , "trait-implementations" ) ;
1051
+ write ! ( w, "<div id=\" trait-implementations-list\" >{}</div>" , impls) ;
1052
+ }
1053
+
1054
+ if !synthetic. is_empty ( ) {
1055
+ write_impl_section_heading ( w, "Auto Trait Implementations" , "synthetic-implementations" ) ;
1056
+ w. write_str ( "<div id=\" synthetic-implementations-list\" >" ) ;
1057
+ render_impls ( cx, w, synthetic, containing_item, false ) ;
1058
+ w. write_str ( "</div>" ) ;
1059
+ }
1060
+
1061
+ if !blanket_impl. is_empty ( ) {
1062
+ write_impl_section_heading ( w, "Blanket Implementations" , "blanket-implementations" ) ;
1063
+ w. write_str ( "<div id=\" blanket-implementations-list\" >" ) ;
1064
+ render_impls ( cx, w, blanket_impl, containing_item, false ) ;
1065
+ w. write_str ( "</div>" ) ;
1066
+ }
1067
+ }
1068
+
1028
1069
fn render_assoc_items (
1029
1070
w : & mut Buffer ,
1030
1071
cx : & mut Context < ' _ > ,
@@ -1054,12 +1095,7 @@ fn render_assoc_items_inner(
1054
1095
let mut tmp_buf = Buffer :: empty_from ( w) ;
1055
1096
let ( render_mode, id) = match what {
1056
1097
AssocItemRender :: All => {
1057
- tmp_buf. write_str (
1058
- "<h2 id=\" implementations\" class=\" small-section-header\" >\
1059
- Implementations\
1060
- <a href=\" #implementations\" class=\" anchor\" ></a>\
1061
- </h2>",
1062
- ) ;
1098
+ write_impl_section_heading ( & mut tmp_buf, "Implementations" , "implementations" ) ;
1063
1099
( RenderMode :: Normal , "implementations-list" . to_owned ( ) )
1064
1100
}
1065
1101
AssocItemRender :: DerefFor { trait_, type_, deref_mut_ } => {
@@ -1068,15 +1104,14 @@ fn render_assoc_items_inner(
1068
1104
if let Some ( def_id) = type_. def_id ( cx. cache ( ) ) {
1069
1105
cx. deref_id_map . insert ( def_id, id. clone ( ) ) ;
1070
1106
}
1071
- write ! (
1072
- tmp_buf,
1073
- "<h2 id=\" {id}\" class=\" small-section-header\" >\
1074
- <span>Methods from {trait_}<Target = {type_}></span>\
1075
- <a href=\" #{id}\" class=\" anchor\" ></a>\
1076
- </h2>",
1077
- id = id,
1078
- trait_ = trait_. print( cx) ,
1079
- type_ = type_. print( cx) ,
1107
+ write_impl_section_heading (
1108
+ & mut tmp_buf,
1109
+ & format ! (
1110
+ "<span>Methods from {trait_}<Target = {type_}></span>" ,
1111
+ trait_ = trait_. print( cx) ,
1112
+ type_ = type_. print( cx) ,
1113
+ ) ,
1114
+ & id,
1080
1115
) ;
1081
1116
( RenderMode :: ForDeref { mut_ : deref_mut_ } , cx. derive_id ( id) )
1082
1117
}
@@ -1128,44 +1163,7 @@ fn render_assoc_items_inner(
1128
1163
let ( blanket_impl, concrete) : ( Vec < & & Impl > , _ ) =
1129
1164
concrete. into_iter ( ) . partition ( |t| t. inner_impl ( ) . kind . is_blanket ( ) ) ;
1130
1165
1131
- let mut impls = Buffer :: empty_from ( w) ;
1132
- render_impls ( cx, & mut impls, & concrete, containing_item, true ) ;
1133
- let impls = impls. into_inner ( ) ;
1134
- if !impls. is_empty ( ) {
1135
- write ! (
1136
- w,
1137
- "<h2 id=\" trait-implementations\" class=\" small-section-header\" >\
1138
- Trait Implementations\
1139
- <a href=\" #trait-implementations\" class=\" anchor\" ></a>\
1140
- </h2>\
1141
- <div id=\" trait-implementations-list\" >{}</div>",
1142
- impls
1143
- ) ;
1144
- }
1145
-
1146
- if !synthetic. is_empty ( ) {
1147
- w. write_str (
1148
- "<h2 id=\" synthetic-implementations\" class=\" small-section-header\" >\
1149
- Auto Trait Implementations\
1150
- <a href=\" #synthetic-implementations\" class=\" anchor\" ></a>\
1151
- </h2>\
1152
- <div id=\" synthetic-implementations-list\" >",
1153
- ) ;
1154
- render_impls ( cx, w, & synthetic, containing_item, false ) ;
1155
- w. write_str ( "</div>" ) ;
1156
- }
1157
-
1158
- if !blanket_impl. is_empty ( ) {
1159
- w. write_str (
1160
- "<h2 id=\" blanket-implementations\" class=\" small-section-header\" >\
1161
- Blanket Implementations\
1162
- <a href=\" #blanket-implementations\" class=\" anchor\" ></a>\
1163
- </h2>\
1164
- <div id=\" blanket-implementations-list\" >",
1165
- ) ;
1166
- render_impls ( cx, w, & blanket_impl, containing_item, false ) ;
1167
- w. write_str ( "</div>" ) ;
1168
- }
1166
+ render_all_impls ( w, cx, containing_item, & concrete, & synthetic, & blanket_impl) ;
1169
1167
}
1170
1168
}
1171
1169
0 commit comments