@@ -290,19 +290,66 @@ impl AllTypes {
290
290
} ;
291
291
}
292
292
}
293
- }
294
293
295
- impl AllTypes {
294
+ fn item_sections ( & self ) -> FxHashSet < ItemSection > {
295
+ let mut sections = FxHashSet :: default ( ) ;
296
+
297
+ if !self . structs . is_empty ( ) {
298
+ sections. insert ( ItemSection :: Structs ) ;
299
+ }
300
+ if !self . enums . is_empty ( ) {
301
+ sections. insert ( ItemSection :: Enums ) ;
302
+ }
303
+ if !self . unions . is_empty ( ) {
304
+ sections. insert ( ItemSection :: Unions ) ;
305
+ }
306
+ if !self . primitives . is_empty ( ) {
307
+ sections. insert ( ItemSection :: PrimitiveTypes ) ;
308
+ }
309
+ if !self . traits . is_empty ( ) {
310
+ sections. insert ( ItemSection :: Traits ) ;
311
+ }
312
+ if !self . macros . is_empty ( ) {
313
+ sections. insert ( ItemSection :: Macros ) ;
314
+ }
315
+ if !self . functions . is_empty ( ) {
316
+ sections. insert ( ItemSection :: Functions ) ;
317
+ }
318
+ if !self . typedefs . is_empty ( ) {
319
+ sections. insert ( ItemSection :: TypeDefinitions ) ;
320
+ }
321
+ if !self . opaque_tys . is_empty ( ) {
322
+ sections. insert ( ItemSection :: OpaqueTypes ) ;
323
+ }
324
+ if !self . statics . is_empty ( ) {
325
+ sections. insert ( ItemSection :: Statics ) ;
326
+ }
327
+ if !self . constants . is_empty ( ) {
328
+ sections. insert ( ItemSection :: Constants ) ;
329
+ }
330
+ if !self . attributes . is_empty ( ) {
331
+ sections. insert ( ItemSection :: AttributeMacros ) ;
332
+ }
333
+ if !self . derives . is_empty ( ) {
334
+ sections. insert ( ItemSection :: DeriveMacros ) ;
335
+ }
336
+ if !self . trait_aliases . is_empty ( ) {
337
+ sections. insert ( ItemSection :: TraitAliases ) ;
338
+ }
339
+
340
+ sections
341
+ }
342
+
296
343
fn print ( self , f : & mut Buffer ) {
297
- fn print_entries ( f : & mut Buffer , e : & FxHashSet < ItemEntry > , title : & str ) {
344
+ fn print_entries ( f : & mut Buffer , e : & FxHashSet < ItemEntry > , kind : ItemSection ) {
298
345
if !e. is_empty ( ) {
299
346
let mut e: Vec < & ItemEntry > = e. iter ( ) . collect ( ) ;
300
347
e. sort ( ) ;
301
348
write ! (
302
349
f,
303
- "<h3 id=\" {}\" >{}</h3><ul class=\" all-items\" >" ,
304
- title . replace ( ' ' , "-" ) , // IDs cannot contain whitespaces.
305
- title
350
+ "<h3 id=\" {id }\" >{title }</h3><ul class=\" all-items\" >" ,
351
+ id = kind . id ( ) ,
352
+ title = kind . name ( ) ,
306
353
) ;
307
354
308
355
for s in e. iter ( ) {
@@ -320,20 +367,20 @@ impl AllTypes {
320
367
) ;
321
368
// Note: print_entries does not escape the title, because we know the current set of titles
322
369
// doesn't require escaping.
323
- print_entries ( f, & self . structs , " Structs" ) ;
324
- print_entries ( f, & self . enums , " Enums" ) ;
325
- print_entries ( f, & self . unions , " Unions" ) ;
326
- print_entries ( f, & self . primitives , "Primitives" ) ;
327
- print_entries ( f, & self . traits , " Traits" ) ;
328
- print_entries ( f, & self . macros , " Macros" ) ;
329
- print_entries ( f, & self . attributes , "Attribute Macros" ) ;
330
- print_entries ( f, & self . derives , "Derive Macros" ) ;
331
- print_entries ( f, & self . functions , " Functions" ) ;
332
- print_entries ( f, & self . typedefs , "Typedefs" ) ;
333
- print_entries ( f, & self . trait_aliases , "Trait Aliases" ) ;
334
- print_entries ( f, & self . opaque_tys , "Opaque Types" ) ;
335
- print_entries ( f, & self . statics , " Statics" ) ;
336
- print_entries ( f, & self . constants , " Constants" ) ;
370
+ print_entries ( f, & self . structs , ItemSection :: Structs ) ;
371
+ print_entries ( f, & self . enums , ItemSection :: Enums ) ;
372
+ print_entries ( f, & self . unions , ItemSection :: Unions ) ;
373
+ print_entries ( f, & self . primitives , ItemSection :: PrimitiveTypes ) ;
374
+ print_entries ( f, & self . traits , ItemSection :: Traits ) ;
375
+ print_entries ( f, & self . macros , ItemSection :: Macros ) ;
376
+ print_entries ( f, & self . attributes , ItemSection :: AttributeMacros ) ;
377
+ print_entries ( f, & self . derives , ItemSection :: DeriveMacros ) ;
378
+ print_entries ( f, & self . functions , ItemSection :: Functions ) ;
379
+ print_entries ( f, & self . typedefs , ItemSection :: TypeDefinitions ) ;
380
+ print_entries ( f, & self . trait_aliases , ItemSection :: TraitAliases ) ;
381
+ print_entries ( f, & self . opaque_tys , ItemSection :: OpaqueTypes ) ;
382
+ print_entries ( f, & self . statics , ItemSection :: Statics ) ;
383
+ print_entries ( f, & self . constants , ItemSection :: Constants ) ;
337
384
}
338
385
}
339
386
@@ -2468,7 +2515,7 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
2468
2515
}
2469
2516
2470
2517
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
2471
- enum ItemSection {
2518
+ pub ( crate ) enum ItemSection {
2472
2519
Reexports ,
2473
2520
PrimitiveTypes ,
2474
2521
Modules ,
@@ -2620,25 +2667,11 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
2620
2667
}
2621
2668
}
2622
2669
2623
- fn sidebar_module ( buf : & mut Buffer , items : & [ clean :: Item ] ) {
2670
+ pub ( crate ) fn sidebar_module_like ( buf : & mut Buffer , item_sections_in_use : FxHashSet < ItemSection > ) {
2624
2671
use std:: fmt:: Write as _;
2625
2672
2626
2673
let mut sidebar = String :: new ( ) ;
2627
2674
2628
- let item_sections_in_use: FxHashSet < _ > = items
2629
- . iter ( )
2630
- . filter ( |it| {
2631
- !it. is_stripped ( )
2632
- && it
2633
- . name
2634
- . or_else ( || {
2635
- if let clean:: ImportItem ( ref i) = * it. kind &&
2636
- let clean:: ImportKind :: Simple ( s) = i. kind { Some ( s) } else { None }
2637
- } )
2638
- . is_some ( )
2639
- } )
2640
- . map ( |it| item_ty_to_section ( it. type_ ( ) ) )
2641
- . collect ( ) ;
2642
2675
for & sec in ItemSection :: ALL . iter ( ) . filter ( |sec| item_sections_in_use. contains ( sec) ) {
2643
2676
let _ = write ! ( sidebar, "<li><a href=\" #{}\" >{}</a></li>" , sec. id( ) , sec. name( ) ) ;
2644
2677
}
@@ -2656,6 +2689,25 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
2656
2689
}
2657
2690
}
2658
2691
2692
+ fn sidebar_module ( buf : & mut Buffer , items : & [ clean:: Item ] ) {
2693
+ let item_sections_in_use: FxHashSet < _ > = items
2694
+ . iter ( )
2695
+ . filter ( |it| {
2696
+ !it. is_stripped ( )
2697
+ && it
2698
+ . name
2699
+ . or_else ( || {
2700
+ if let clean:: ImportItem ( ref i) = * it. kind &&
2701
+ let clean:: ImportKind :: Simple ( s) = i. kind { Some ( s) } else { None }
2702
+ } )
2703
+ . is_some ( )
2704
+ } )
2705
+ . map ( |it| item_ty_to_section ( it. type_ ( ) ) )
2706
+ . collect ( ) ;
2707
+
2708
+ sidebar_module_like ( buf, item_sections_in_use) ;
2709
+ }
2710
+
2659
2711
fn sidebar_foreign_type ( cx : & Context < ' _ > , buf : & mut Buffer , it : & clean:: Item ) {
2660
2712
let mut sidebar = Buffer :: new ( ) ;
2661
2713
sidebar_assoc_items ( cx, & mut sidebar, it) ;
0 commit comments