@@ -2409,33 +2409,124 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
2409
2409
}
2410
2410
}
2411
2411
2412
- fn item_ty_to_strs ( ty : ItemType ) -> ( & ' static str , & ' static str ) {
2412
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
2413
+ enum ItemSection {
2414
+ Reexports ,
2415
+ Modules ,
2416
+ Structs ,
2417
+ Unions ,
2418
+ Enums ,
2419
+ Functions ,
2420
+ TypeDefinitions ,
2421
+ Statics ,
2422
+ Constants ,
2423
+ Traits ,
2424
+ Implementations ,
2425
+ TypeMethods ,
2426
+ Methods ,
2427
+ StructFields ,
2428
+ Variants ,
2429
+ Macros ,
2430
+ PrimitiveTypes ,
2431
+ AssociatedTypes ,
2432
+ AssociatedConstants ,
2433
+ ForeignTypes ,
2434
+ Keywords ,
2435
+ OpaqueTypes ,
2436
+ AttributeMacros ,
2437
+ DeriveMacros ,
2438
+ TraitAliases ,
2439
+ }
2440
+
2441
+ impl ItemSection {
2442
+ fn id ( self ) -> & ' static str {
2443
+ match self {
2444
+ Self :: Reexports => "reexports" ,
2445
+ Self :: Modules => "modules" ,
2446
+ Self :: Structs => "structs" ,
2447
+ Self :: Unions => "unions" ,
2448
+ Self :: Enums => "enums" ,
2449
+ Self :: Functions => "functions" ,
2450
+ Self :: TypeDefinitions => "types" ,
2451
+ Self :: Statics => "statics" ,
2452
+ Self :: Constants => "constants" ,
2453
+ Self :: Traits => "traits" ,
2454
+ Self :: Implementations => "impls" ,
2455
+ Self :: TypeMethods => "tymethods" ,
2456
+ Self :: Methods => "methods" ,
2457
+ Self :: StructFields => "fields" ,
2458
+ Self :: Variants => "variants" ,
2459
+ Self :: Macros => "macros" ,
2460
+ Self :: PrimitiveTypes => "primitives" ,
2461
+ Self :: AssociatedTypes => "associated-types" ,
2462
+ Self :: AssociatedConstants => "associated-consts" ,
2463
+ Self :: ForeignTypes => "foreign-types" ,
2464
+ Self :: Keywords => "keywords" ,
2465
+ Self :: OpaqueTypes => "opaque-types" ,
2466
+ Self :: AttributeMacros => "attributes" ,
2467
+ Self :: DeriveMacros => "derives" ,
2468
+ Self :: TraitAliases => "trait-aliases" ,
2469
+ }
2470
+ }
2471
+
2472
+ fn name ( self ) -> & ' static str {
2473
+ match self {
2474
+ Self :: Reexports => "Re-exports" ,
2475
+ Self :: Modules => "Modules" ,
2476
+ Self :: Structs => "Structs" ,
2477
+ Self :: Unions => "Unions" ,
2478
+ Self :: Enums => "Enums" ,
2479
+ Self :: Functions => "Functions" ,
2480
+ Self :: TypeDefinitions => "Type Definitions" ,
2481
+ Self :: Statics => "Statics" ,
2482
+ Self :: Constants => "Constants" ,
2483
+ Self :: Traits => "Traits" ,
2484
+ Self :: Implementations => "Implementations" ,
2485
+ Self :: TypeMethods => "Type Methods" ,
2486
+ Self :: Methods => "Methods" ,
2487
+ Self :: StructFields => "Struct Fields" ,
2488
+ Self :: Variants => "Variants" ,
2489
+ Self :: Macros => "Macros" ,
2490
+ Self :: PrimitiveTypes => "Primitive Types" ,
2491
+ Self :: AssociatedTypes => "Associated Types" ,
2492
+ Self :: AssociatedConstants => "Associated Constants" ,
2493
+ Self :: ForeignTypes => "Foreign Types" ,
2494
+ Self :: Keywords => "Keywords" ,
2495
+ Self :: OpaqueTypes => "Opaque Types" ,
2496
+ Self :: AttributeMacros => "Attribute Macros" ,
2497
+ Self :: DeriveMacros => "Derive Macros" ,
2498
+ Self :: TraitAliases => "Trait aliases" ,
2499
+ }
2500
+ }
2501
+ }
2502
+
2503
+ fn item_ty_to_section ( ty : ItemType ) -> ItemSection {
2413
2504
match ty {
2414
- ItemType :: ExternCrate | ItemType :: Import => ( "reexports" , "Re-exports" ) ,
2415
- ItemType :: Module => ( "modules" , " Modules" ) ,
2416
- ItemType :: Struct => ( "structs" , " Structs" ) ,
2417
- ItemType :: Union => ( "unions" , " Unions" ) ,
2418
- ItemType :: Enum => ( "enums" , " Enums" ) ,
2419
- ItemType :: Function => ( "functions" , " Functions" ) ,
2420
- ItemType :: Typedef => ( "types" , "Type Definitions" ) ,
2421
- ItemType :: Static => ( "statics" , " Statics" ) ,
2422
- ItemType :: Constant => ( "constants" , " Constants" ) ,
2423
- ItemType :: Trait => ( "traits" , " Traits" ) ,
2424
- ItemType :: Impl => ( "impls" , " Implementations" ) ,
2425
- ItemType :: TyMethod => ( "tymethods" , "Type Methods" ) ,
2426
- ItemType :: Method => ( "methods" , " Methods" ) ,
2427
- ItemType :: StructField => ( "fields" , "Struct Fields" ) ,
2428
- ItemType :: Variant => ( "variants" , " Variants" ) ,
2429
- ItemType :: Macro => ( "macros" , " Macros" ) ,
2430
- ItemType :: Primitive => ( "primitives" , "Primitive Types" ) ,
2431
- ItemType :: AssocType => ( "associated-types" , "Associated Types" ) ,
2432
- ItemType :: AssocConst => ( "associated-consts" , "Associated Constants" ) ,
2433
- ItemType :: ForeignType => ( "foreign-types" , "Foreign Types" ) ,
2434
- ItemType :: Keyword => ( "keywords" , " Keywords" ) ,
2435
- ItemType :: OpaqueTy => ( "opaque-types" , "Opaque Types" ) ,
2436
- ItemType :: ProcAttribute => ( "attributes" , "Attribute Macros" ) ,
2437
- ItemType :: ProcDerive => ( "derives" , "Derive Macros" ) ,
2438
- ItemType :: TraitAlias => ( "trait-aliases" , "Trait aliases" ) ,
2505
+ ItemType :: ExternCrate | ItemType :: Import => ItemSection :: Reexports ,
2506
+ ItemType :: Module => ItemSection :: Modules ,
2507
+ ItemType :: Struct => ItemSection :: Structs ,
2508
+ ItemType :: Union => ItemSection :: Unions ,
2509
+ ItemType :: Enum => ItemSection :: Enums ,
2510
+ ItemType :: Function => ItemSection :: Functions ,
2511
+ ItemType :: Typedef => ItemSection :: TypeDefinitions ,
2512
+ ItemType :: Static => ItemSection :: Statics ,
2513
+ ItemType :: Constant => ItemSection :: Constants ,
2514
+ ItemType :: Trait => ItemSection :: Traits ,
2515
+ ItemType :: Impl => ItemSection :: Implementations ,
2516
+ ItemType :: TyMethod => ItemSection :: TypeMethods ,
2517
+ ItemType :: Method => ItemSection :: Methods ,
2518
+ ItemType :: StructField => ItemSection :: StructFields ,
2519
+ ItemType :: Variant => ItemSection :: Variants ,
2520
+ ItemType :: Macro => ItemSection :: Macros ,
2521
+ ItemType :: Primitive => ItemSection :: PrimitiveTypes ,
2522
+ ItemType :: AssocType => ItemSection :: AssociatedTypes ,
2523
+ ItemType :: AssocConst => ItemSection :: AssociatedConstants ,
2524
+ ItemType :: ForeignType => ItemSection :: ForeignTypes ,
2525
+ ItemType :: Keyword => ItemSection :: Keywords ,
2526
+ ItemType :: OpaqueTy => ItemSection :: OpaqueTypes ,
2527
+ ItemType :: ProcAttribute => ItemSection :: AttributeMacros ,
2528
+ ItemType :: ProcDerive => ItemSection :: DeriveMacros ,
2529
+ ItemType :: TraitAlias => ItemSection :: TraitAliases ,
2439
2530
ItemType :: Generic => unreachable ! ( ) ,
2440
2531
}
2441
2532
}
@@ -2449,8 +2540,8 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
2449
2540
&& ( it. type_ ( ) == ItemType :: ExternCrate
2450
2541
|| ( it. type_ ( ) == ItemType :: Import && !it. is_stripped ( ) ) )
2451
2542
} ) {
2452
- let ( id , name ) = item_ty_to_strs ( ItemType :: Import ) ;
2453
- sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , id , name) ) ;
2543
+ let sec = item_ty_to_section ( ItemType :: Import ) ;
2544
+ sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , sec . id ( ) , sec . name( ) ) ) ;
2454
2545
}
2455
2546
2456
2547
// ordering taken from item_module, reorder, where it prioritized elements in a certain order
@@ -2478,8 +2569,8 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
2478
2569
ItemType :: Keyword ,
2479
2570
] {
2480
2571
if items. iter ( ) . any ( |it| !it. is_stripped ( ) && it. type_ ( ) == myty && it. name . is_some ( ) ) {
2481
- let ( id , name ) = item_ty_to_strs ( myty) ;
2482
- sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , id , name) ) ;
2572
+ let sec = item_ty_to_section ( myty) ;
2573
+ sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , sec . id ( ) , sec . name( ) ) ) ;
2483
2574
}
2484
2575
}
2485
2576
0 commit comments