@@ -1208,29 +1208,29 @@ impl<'a> AssocItemLink<'a> {
1208
1208
}
1209
1209
}
1210
1210
1211
- pub fn write_section_heading (
1212
- w : & mut impl fmt :: Write ,
1213
- title : & str ,
1214
- id : & str ,
1215
- extra_class : Option < & str > ,
1216
- extra : impl fmt:: Display ,
1217
- ) {
1218
- let ( extra_class, whitespace) = match extra_class {
1219
- Some ( extra) => ( extra, " " ) ,
1220
- None => ( "" , "" ) ,
1221
- } ;
1222
- write ! (
1223
- w,
1224
- "<h2 id=\" {id}\" class=\" {extra_class}{whitespace}section-header\" >\
1211
+ pub fn write_section_heading < ' a > (
1212
+ title : & ' a str ,
1213
+ id : & ' a str ,
1214
+ extra_class : Option < & ' a str > ,
1215
+ extra : impl fmt :: Display + ' a ,
1216
+ ) -> impl fmt:: Display + ' a {
1217
+ fmt :: from_fn ( move |w| {
1218
+ let ( extra_class, whitespace) = match extra_class {
1219
+ Some ( extra) => ( extra, " " ) ,
1220
+ None => ( "" , "" ) ,
1221
+ } ;
1222
+ write ! (
1223
+ w,
1224
+ "<h2 id=\" {id}\" class=\" {extra_class}{whitespace}section-header\" >\
1225
1225
{title}\
1226
1226
<a href=\" #{id}\" class=\" anchor\" >§</a>\
1227
1227
</h2>{extra}",
1228
- )
1229
- . unwrap ( ) ;
1228
+ )
1229
+ } )
1230
1230
}
1231
1231
1232
- fn write_impl_section_heading ( w : & mut impl fmt :: Write , title : & str , id : & str ) {
1233
- write_section_heading ( w , title, id, None , "" )
1232
+ fn write_impl_section_heading < ' a > ( title : & ' a str , id : & ' a str ) -> impl fmt :: Display + ' a {
1233
+ write_section_heading ( title, id, None , "" )
1234
1234
}
1235
1235
1236
1236
pub ( crate ) fn render_all_impls (
@@ -1247,24 +1247,32 @@ pub(crate) fn render_all_impls(
1247
1247
buf
1248
1248
} ;
1249
1249
if !impls. is_empty ( ) {
1250
- write_impl_section_heading ( & mut w, "Trait Implementations" , "trait-implementations" ) ;
1251
- write ! ( w, "<div id=\" trait-implementations-list\" >{impls}</div>" ) . unwrap ( ) ;
1250
+ write ! (
1251
+ w,
1252
+ "{}<div id=\" trait-implementations-list\" >{impls}</div>" ,
1253
+ write_impl_section_heading( "Trait Implementations" , "trait-implementations" )
1254
+ )
1255
+ . unwrap ( ) ;
1252
1256
}
1253
1257
1254
1258
if !synthetic. is_empty ( ) {
1255
- write_impl_section_heading (
1256
- & mut w,
1257
- "Auto Trait Implementations " ,
1258
- " synthetic-implementations",
1259
- ) ;
1260
- w . write_str ( "<div id= \" synthetic-implementations-list \" >" ) . unwrap ( ) ;
1259
+ write ! (
1260
+ w,
1261
+ "{}<div id= \" synthetic-implementations-list \" > " ,
1262
+ write_impl_section_heading ( "Auto Trait Implementations" , " synthetic-implementations", )
1263
+ )
1264
+ . unwrap ( ) ;
1261
1265
render_impls ( cx, & mut w, synthetic, containing_item, false ) ;
1262
1266
w. write_str ( "</div>" ) . unwrap ( ) ;
1263
1267
}
1264
1268
1265
1269
if !blanket_impl. is_empty ( ) {
1266
- write_impl_section_heading ( & mut w, "Blanket Implementations" , "blanket-implementations" ) ;
1267
- w. write_str ( "<div id=\" blanket-implementations-list\" >" ) . unwrap ( ) ;
1270
+ write ! (
1271
+ w,
1272
+ "{}<div id=\" blanket-implementations-list\" >" ,
1273
+ write_impl_section_heading( "Blanket Implementations" , "blanket-implementations" )
1274
+ )
1275
+ . unwrap ( ) ;
1268
1276
render_impls ( cx, & mut w, blanket_impl, containing_item, false ) ;
1269
1277
w. write_str ( "</div>" ) . unwrap ( ) ;
1270
1278
}
@@ -1301,25 +1309,34 @@ fn render_assoc_items_inner(
1301
1309
let mut tmp_buf = String :: new ( ) ;
1302
1310
let ( render_mode, id, class_html) = match what {
1303
1311
AssocItemRender :: All => {
1304
- write_impl_section_heading ( & mut tmp_buf, "Implementations" , "implementations" ) ;
1312
+ write_str (
1313
+ & mut tmp_buf,
1314
+ format_args ! (
1315
+ "{}" ,
1316
+ write_impl_section_heading( "Implementations" , "implementations" )
1317
+ ) ,
1318
+ ) ;
1305
1319
( RenderMode :: Normal , "implementations-list" . to_owned ( ) , "" )
1306
1320
}
1307
1321
AssocItemRender :: DerefFor { trait_, type_, deref_mut_ } => {
1308
1322
let id =
1309
1323
cx. derive_id ( small_url_encode ( format ! ( "deref-methods-{:#}" , type_. print( cx) ) ) ) ;
1310
1324
let derived_id = cx. derive_id ( & id) ;
1311
- tmp_buf. push_str ( "<details class=\" toggle big-toggle\" open><summary>" ) ;
1312
1325
close_tags. push ( "</details>" ) ;
1313
- write_impl_section_heading (
1326
+ write_str (
1314
1327
& mut tmp_buf,
1315
- & format ! (
1316
- "<span>Methods from {trait_}<Target = {type_}></span>" ,
1317
- trait_ = trait_. print( cx) ,
1318
- type_ = type_. print( cx) ,
1328
+ format_args ! (
1329
+ "<details class=\" toggle big-toggle\" open><summary>{}</summary>" ,
1330
+ write_impl_section_heading(
1331
+ & format!(
1332
+ "<span>Methods from {trait_}<Target = {type_}></span>" ,
1333
+ trait_ = trait_. print( cx) ,
1334
+ type_ = type_. print( cx) ,
1335
+ ) ,
1336
+ & id,
1337
+ )
1319
1338
) ,
1320
- & id,
1321
1339
) ;
1322
- tmp_buf. push_str ( "</summary>" ) ;
1323
1340
if let Some ( def_id) = type_. def_id ( cx. cache ( ) ) {
1324
1341
cx. deref_id_map . borrow_mut ( ) . insert ( def_id, id) ;
1325
1342
}
0 commit comments