@@ -2498,7 +2498,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2498
2498
2499
2499
if !foreign. is_empty ( ) {
2500
2500
write ! ( w, "
2501
- <h2 id='foreign-impls' class='section-header'>
2501
+ <h2 id='foreign-impls' class='small- section-header'>
2502
2502
Implementations on Foreign Types<a href='#foreign-impls' class='anchor'></a>
2503
2503
</h2>
2504
2504
" ) ?;
@@ -3591,7 +3591,8 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
3591
3591
let mut links = HashSet :: new ( ) ;
3592
3592
let ret = v. iter ( )
3593
3593
. filter_map ( |i| if let Some ( ref i) = i. inner_impl ( ) . trait_ {
3594
- let out = format ! ( "{:#}" , i) . replace ( "<" , "<" ) . replace ( ">" , ">" ) ;
3594
+ let i_display = format ! ( "{:#}" , i) ;
3595
+ let out = Escape ( & i_display) ;
3595
3596
let encoded = small_url_encode ( & format ! ( "{:#}" , i) ) ;
3596
3597
let generated = format ! ( "<a href=\" #impl-{}\" >{}</a>" , encoded, out) ;
3597
3598
if !links. contains ( & generated) && links. insert ( generated. clone ( ) ) {
@@ -3617,11 +3618,12 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
3617
3618
fn sidebar_struct ( fmt : & mut fmt:: Formatter , it : & clean:: Item ,
3618
3619
s : & clean:: Struct ) -> fmt:: Result {
3619
3620
let mut sidebar = String :: new ( ) ;
3621
+ let fields = get_struct_fields_name ( & s. fields ) ;
3620
3622
3621
- if s. fields . iter ( )
3622
- . any ( |f| if let clean:: StructFieldItem ( ..) = f. inner { true } else { false } ) {
3623
+ if !fields. is_empty ( ) {
3623
3624
if let doctree:: Plain = s. struct_type {
3624
- sidebar. push_str ( "<li><a href=\" #fields\" >Fields</a></li>" ) ;
3625
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #fields\" >Fields</a>\
3626
+ <div class=\" sidebar-links\" >{}</div>", fields) ) ;
3625
3627
}
3626
3628
}
3627
3629
@@ -3633,40 +3635,122 @@ fn sidebar_struct(fmt: &mut fmt::Formatter, it: &clean::Item,
3633
3635
Ok ( ( ) )
3634
3636
}
3635
3637
3638
+ fn extract_for_impl_name ( item : & clean:: Item ) -> Option < ( String , String ) > {
3639
+ match item. inner {
3640
+ clean:: ItemEnum :: ImplItem ( ref i) => {
3641
+ if let Some ( ref trait_) = i. trait_ {
3642
+ Some ( ( format ! ( "{:#}" , i. for_) , format ! ( "{:#}" , trait_) ) )
3643
+ } else {
3644
+ None
3645
+ }
3646
+ } ,
3647
+ _ => None ,
3648
+ }
3649
+ }
3650
+
3636
3651
fn sidebar_trait ( fmt : & mut fmt:: Formatter , it : & clean:: Item ,
3637
3652
t : & clean:: Trait ) -> fmt:: Result {
3638
3653
let mut sidebar = String :: new ( ) ;
3639
3654
3640
- let has_types = t. items . iter ( ) . any ( |m| m. is_associated_type ( ) ) ;
3641
- let has_consts = t. items . iter ( ) . any ( |m| m. is_associated_const ( ) ) ;
3642
- let has_required = t. items . iter ( ) . any ( |m| m. is_ty_method ( ) ) ;
3643
- let has_provided = t. items . iter ( ) . any ( |m| m. is_method ( ) ) ;
3655
+ let types = t. items
3656
+ . iter ( )
3657
+ . filter_map ( |m| {
3658
+ match m. name {
3659
+ Some ( ref name) if m. is_associated_type ( ) => {
3660
+ Some ( format ! ( "<a href=\" #associatedtype.{name}\" >{name}</a>" ,
3661
+ name=name) )
3662
+ }
3663
+ _ => None ,
3664
+ }
3665
+ } )
3666
+ . collect :: < String > ( ) ;
3667
+ let consts = t. items
3668
+ . iter ( )
3669
+ . filter_map ( |m| {
3670
+ match m. name {
3671
+ Some ( ref name) if m. is_associated_const ( ) => {
3672
+ Some ( format ! ( "<a href=\" #associatedconstant.{name}\" >{name}</a>" ,
3673
+ name=name) )
3674
+ }
3675
+ _ => None ,
3676
+ }
3677
+ } )
3678
+ . collect :: < String > ( ) ;
3679
+ let required = t. items
3680
+ . iter ( )
3681
+ . filter_map ( |m| {
3682
+ match m. name {
3683
+ Some ( ref name) if m. is_ty_method ( ) => {
3684
+ Some ( format ! ( "<a href=\" #tymethod.{name}\" >{name}</a>" ,
3685
+ name=name) )
3686
+ }
3687
+ _ => None ,
3688
+ }
3689
+ } )
3690
+ . collect :: < String > ( ) ;
3691
+ let provided = t. items
3692
+ . iter ( )
3693
+ . filter_map ( |m| {
3694
+ match m. name {
3695
+ Some ( ref name) if m. is_method ( ) => {
3696
+ Some ( format ! ( "<a href=\" #method.{name}\" >{name}</a>" , name=name) )
3697
+ }
3698
+ _ => None ,
3699
+ }
3700
+ } )
3701
+ . collect :: < String > ( ) ;
3644
3702
3645
- if has_types {
3646
- sidebar. push_str ( "<li><a href=\" #associated-types\" >Associated Types</a></li>" ) ;
3703
+ if !types. is_empty ( ) {
3704
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #associated-types\" >\
3705
+ Associated Types</a><div class=\" sidebar-links\" >{}</div>",
3706
+ types) ) ;
3647
3707
}
3648
- if has_consts {
3649
- sidebar. push_str ( "<li><a href=\" #associated-const\" >Associated Constants</a></li>" ) ;
3708
+ if !consts. is_empty ( ) {
3709
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #associated-const\" >\
3710
+ Associated Constants</a><div class=\" sidebar-links\" >{}</div>",
3711
+ consts) ) ;
3650
3712
}
3651
- if has_required {
3652
- sidebar. push_str ( "<li><a href=\" #required-methods\" >Required Methods</a></li>" ) ;
3713
+ if !required. is_empty ( ) {
3714
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #required-methods\" >\
3715
+ Required Methods</a><div class=\" sidebar-links\" >{}</div>",
3716
+ required) ) ;
3653
3717
}
3654
- if has_provided {
3655
- sidebar. push_str ( "<li><a href=\" #provided-methods\" >Provided Methods</a></li>" ) ;
3718
+ if !provided. is_empty ( ) {
3719
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #provided-methods\" >\
3720
+ Provided Methods</a><div class=\" sidebar-links\" >{}</div>",
3721
+ provided) ) ;
3656
3722
}
3657
3723
3658
3724
let c = cache ( ) ;
3659
3725
3660
3726
if let Some ( implementors) = c. implementors . get ( & it. def_id ) {
3661
- if implementors. iter ( ) . any ( |i| i. impl_ . for_ . def_id ( )
3662
- . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3663
- {
3664
- sidebar. push_str ( "<li><a href=\" #foreign-impls\" >\
3665
- Implementations on Foreign Types</a></li>") ;
3666
- }
3667
- }
3668
-
3669
- sidebar. push_str ( "<li><a href=\" #implementors\" >Implementors</a></li>" ) ;
3727
+ let res = implementors. iter ( )
3728
+ . filter ( |i| i. impl_ . for_ . def_id ( )
3729
+ . map_or ( false , |d| !c. paths . contains_key ( & d) ) )
3730
+ . filter_map ( |i| {
3731
+ if let Some ( item) = implementor2item ( & c, i) {
3732
+ match extract_for_impl_name ( & item) {
3733
+ Some ( ( ref name, ref url) ) => {
3734
+ Some ( format ! ( "<a href=\" #impl-{}\" >{}</a>" ,
3735
+ small_url_encode( url) ,
3736
+ Escape ( name) ) )
3737
+ }
3738
+ _ => None ,
3739
+ }
3740
+ } else {
3741
+ None
3742
+ }
3743
+ } )
3744
+ . collect :: < String > ( ) ;
3745
+ if !res. is_empty ( ) {
3746
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #foreign-impls\" >\
3747
+ Implementations on Foreign Types</a><div \
3748
+ class=\" sidebar-links\" >{}</div>",
3749
+ res) ) ;
3750
+ }
3751
+ }
3752
+
3753
+ sidebar. push_str ( "<a class=\" sidebar-title\" href=\" #implementors\" >Implementors</a>" ) ;
3670
3754
3671
3755
sidebar. push_str ( & sidebar_assoc_items ( it) ) ;
3672
3756
@@ -3693,13 +3777,29 @@ fn sidebar_typedef(fmt: &mut fmt::Formatter, it: &clean::Item,
3693
3777
Ok ( ( ) )
3694
3778
}
3695
3779
3780
+ fn get_struct_fields_name ( fields : & [ clean:: Item ] ) -> String {
3781
+ fields. iter ( )
3782
+ . filter ( |f| if let clean:: StructFieldItem ( ..) = f. inner {
3783
+ true
3784
+ } else {
3785
+ false
3786
+ } )
3787
+ . filter_map ( |f| match f. name {
3788
+ Some ( ref name) => Some ( format ! ( "<a href=\" #structfield.{name}\" >\
3789
+ {name}</a>", name=name) ) ,
3790
+ _ => None ,
3791
+ } )
3792
+ . collect ( )
3793
+ }
3794
+
3696
3795
fn sidebar_union ( fmt : & mut fmt:: Formatter , it : & clean:: Item ,
3697
3796
u : & clean:: Union ) -> fmt:: Result {
3698
3797
let mut sidebar = String :: new ( ) ;
3798
+ let fields = get_struct_fields_name ( & u. fields ) ;
3699
3799
3700
- if u . fields . iter ( )
3701
- . any ( |f| if let clean :: StructFieldItem ( .. ) = f . inner { true } else { false } ) {
3702
- sidebar . push_str ( "<li><a href =\" #fields \" >Fields</a></li>" ) ;
3800
+ if ! fields. is_empty ( ) {
3801
+ sidebar . push_str ( & format ! ( "<a class= \" sidebar-title \" href= \" #fields \" >Fields</a> \
3802
+ <div class =\" sidebar-links \" >{}</div>" , fields ) ) ;
3703
3803
}
3704
3804
3705
3805
sidebar. push_str ( & sidebar_assoc_items ( it) ) ;
@@ -3714,8 +3814,16 @@ fn sidebar_enum(fmt: &mut fmt::Formatter, it: &clean::Item,
3714
3814
e : & clean:: Enum ) -> fmt:: Result {
3715
3815
let mut sidebar = String :: new ( ) ;
3716
3816
3717
- if !e. variants . is_empty ( ) {
3718
- sidebar. push_str ( "<li><a href=\" #variants\" >Variants</a></li>" ) ;
3817
+ let variants = e. variants . iter ( )
3818
+ . filter_map ( |v| match v. name {
3819
+ Some ( ref name) => Some ( format ! ( "<a href=\" #variant.{name}\" >{name}\
3820
+ </a>", name = name) ) ,
3821
+ _ => None ,
3822
+ } )
3823
+ . collect :: < String > ( ) ;
3824
+ if !variants. is_empty ( ) {
3825
+ sidebar. push_str ( & format ! ( "<a class=\" sidebar-title\" href=\" #variants\" >Variants</a>\
3826
+ <div class=\" sidebar-links\" >{}</div>", variants) ) ;
3719
3827
}
3720
3828
3721
3829
sidebar. push_str ( & sidebar_assoc_items ( it) ) ;
0 commit comments