@@ -1811,23 +1811,53 @@ fn get_next_url(used_links: &mut FxHashSet<String>, url: String) -> String {
1811
1811
format ! ( "{}-{}" , url, add)
1812
1812
}
1813
1813
1814
+ struct SidebarLink {
1815
+ name : Symbol ,
1816
+ url : String ,
1817
+ }
1818
+
1819
+ impl fmt:: Display for SidebarLink {
1820
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1821
+ write ! ( f, "<a href=\" #{}\" >{}</a>" , self . url, self . name)
1822
+ }
1823
+ }
1824
+
1825
+ impl PartialEq for SidebarLink {
1826
+ fn eq ( & self , other : & Self ) -> bool {
1827
+ self . url == other. url
1828
+ }
1829
+ }
1830
+
1831
+ impl Eq for SidebarLink { }
1832
+
1833
+ impl PartialOrd for SidebarLink {
1834
+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
1835
+ Some ( self . cmp ( other) )
1836
+ }
1837
+ }
1838
+
1839
+ impl Ord for SidebarLink {
1840
+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
1841
+ self . url . cmp ( & other. url )
1842
+ }
1843
+ }
1844
+
1814
1845
fn get_methods (
1815
1846
i : & clean:: Impl ,
1816
1847
for_deref : bool ,
1817
1848
used_links : & mut FxHashSet < String > ,
1818
1849
deref_mut : bool ,
1819
1850
tcx : TyCtxt < ' _ > ,
1820
- ) -> Vec < String > {
1851
+ ) -> Vec < SidebarLink > {
1821
1852
i. items
1822
1853
. iter ( )
1823
1854
. filter_map ( |item| match item. name {
1824
- Some ( ref name) if !name. is_empty ( ) && item. is_method ( ) => {
1855
+ Some ( name) if !name. is_empty ( ) && item. is_method ( ) => {
1825
1856
if !for_deref || should_render_item ( item, deref_mut, tcx) {
1826
- Some ( format ! (
1827
- "<a href=\" #{}\" >{}</a>" ,
1828
- get_next_url( used_links, format!( "method.{}" , name) ) ,
1829
- name
1830
- ) )
1857
+ Some ( SidebarLink {
1858
+ name,
1859
+ url : get_next_url ( used_links, format ! ( "method.{}" , name) ) ,
1860
+ } )
1831
1861
} else {
1832
1862
None
1833
1863
}
@@ -1837,15 +1867,17 @@ fn get_methods(
1837
1867
. collect :: < Vec < _ > > ( )
1838
1868
}
1839
1869
1840
- fn get_associated_constants ( i : & clean:: Impl , used_links : & mut FxHashSet < String > ) -> Vec < String > {
1870
+ fn get_associated_constants (
1871
+ i : & clean:: Impl ,
1872
+ used_links : & mut FxHashSet < String > ,
1873
+ ) -> Vec < SidebarLink > {
1841
1874
i. items
1842
1875
. iter ( )
1843
1876
. filter_map ( |item| match item. name {
1844
- Some ( ref name) if !name. is_empty ( ) && item. is_associated_const ( ) => Some ( format ! (
1845
- "<a href=\" #{}\" >{}</a>" ,
1846
- get_next_url( used_links, format!( "associatedconstant.{}" , name) ) ,
1847
- name
1848
- ) ) ,
1877
+ Some ( name) if !name. is_empty ( ) && item. is_associated_const ( ) => Some ( SidebarLink {
1878
+ name,
1879
+ url : get_next_url ( used_links, format ! ( "associatedconstant.{}" , name) ) ,
1880
+ } ) ,
1849
1881
_ => None ,
1850
1882
} )
1851
1883
. collect :: < Vec < _ > > ( )
@@ -1910,7 +1942,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
1910
1942
<div class=\" sidebar-links\" >",
1911
1943
) ;
1912
1944
for line in assoc_consts {
1913
- out . push_str ( & line) ;
1945
+ write ! ( out , "{}" , line) ;
1914
1946
}
1915
1947
out. push_str ( "</div>" ) ;
1916
1948
}
@@ -1928,7 +1960,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
1928
1960
<div class=\" sidebar-links\" >",
1929
1961
) ;
1930
1962
for line in methods {
1931
- out . push_str ( & line) ;
1963
+ write ! ( out , "{}" , line) ;
1932
1964
}
1933
1965
out. push_str ( "</div>" ) ;
1934
1966
}
@@ -2063,7 +2095,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
2063
2095
ret. sort ( ) ;
2064
2096
out. push_str ( "<div class=\" sidebar-links\" >" ) ;
2065
2097
for link in ret {
2066
- out . push_str ( & link) ;
2098
+ write ! ( out , "{}" , link) ;
2067
2099
}
2068
2100
out. push_str ( "</div>" ) ;
2069
2101
}
0 commit comments