@@ -66,6 +66,10 @@ use html::markdown::Markdown;
66
66
use html:: markdown;
67
67
use stability_summary;
68
68
69
+ /// A pair of name and its optional document.
70
+ #[ deriving( Clone , Eq , Ord , PartialEq , PartialOrd ) ]
71
+ pub struct NameDoc ( String , Option < String > ) ;
72
+
69
73
/// Major driving force in all rustdoc rendering. This contains information
70
74
/// about where in the tree-like hierarchy rendering is occurring and controls
71
75
/// how the current page is being rendered.
@@ -95,7 +99,7 @@ pub struct Context {
95
99
/// functions), and the value is the list of containers belonging to this
96
100
/// header. This map will change depending on the surrounding context of the
97
101
/// page.
98
- pub sidebar : HashMap < String , Vec < String > > ,
102
+ pub sidebar : HashMap < String , Vec < NameDoc > > ,
99
103
/// This flag indicates whether [src] links should be generated or not. If
100
104
/// the source files are present in the html rendering, then this will be
101
105
/// `true`.
@@ -1245,7 +1249,7 @@ impl Context {
1245
1249
}
1246
1250
}
1247
1251
1248
- fn build_sidebar ( & self , m : & clean:: Module ) -> HashMap < String , Vec < String > > {
1252
+ fn build_sidebar ( & self , m : & clean:: Module ) -> HashMap < String , Vec < NameDoc > > {
1249
1253
let mut map = HashMap :: new ( ) ;
1250
1254
for item in m. items . iter ( ) {
1251
1255
if self . ignore_private_item ( item) { continue }
@@ -1262,7 +1266,7 @@ impl Context {
1262
1266
let short = short. to_string ( ) ;
1263
1267
let v = map. entry ( short) . get ( ) . unwrap_or_else (
1264
1268
|vacant_entry| vacant_entry. insert ( Vec :: with_capacity ( 1 ) ) ) ;
1265
- v. push ( myname) ;
1269
+ v. push ( NameDoc ( myname, Some ( shorter_line ( item . doc_value ( ) ) ) ) ) ;
1266
1270
}
1267
1271
1268
1272
for ( _, items) in map. iter_mut ( ) {
@@ -1476,6 +1480,11 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str {
1476
1480
}
1477
1481
}
1478
1482
1483
+ #[ inline]
1484
+ fn shorter_line ( s : Option < & str > ) -> String {
1485
+ shorter ( s) . replace ( "\n " , " " )
1486
+ }
1487
+
1479
1488
fn document ( w : & mut fmt:: Formatter , item : & clean:: Item ) -> fmt:: Result {
1480
1489
match item. doc_value ( ) {
1481
1490
Some ( s) => {
@@ -2213,21 +2222,22 @@ impl<'a> fmt::String for Sidebar<'a> {
2213
2222
None => return Ok ( ( ) )
2214
2223
} ;
2215
2224
try!( write ! ( w, "<div class='block {}'><h2>{}</h2>" , short, longty) ) ;
2216
- for item in items. iter ( ) {
2225
+ for & NameDoc ( ref name , ref doc ) in items. iter ( ) {
2217
2226
let curty = shortty ( cur) . to_static_str ( ) ;
2218
- let class = if cur. name . as_ref ( ) . unwrap ( ) == item &&
2227
+ let class = if cur. name . as_ref ( ) . unwrap ( ) == name &&
2219
2228
short == curty { "current" } else { "" } ;
2220
- try!( write ! ( w, "<a class='{ty} {class}' href='{href}{path}'> \
2221
- {name}</a>",
2229
+ try!( write ! ( w, "<a class='{ty} {class}' href='{href}{path}' \
2230
+ title='{title}'> {name}</a>",
2222
2231
ty = short,
2223
2232
class = class,
2224
2233
href = if curty == "mod" { "../" } else { "" } ,
2225
2234
path = if short == "mod" {
2226
- format!( "{}/index.html" , item . as_slice( ) )
2235
+ format!( "{}/index.html" , name . as_slice( ) )
2227
2236
} else {
2228
- format!( "{}.{}.html" , short, item . as_slice( ) )
2237
+ format!( "{}.{}.html" , short, name . as_slice( ) )
2229
2238
} ,
2230
- name = item. as_slice( ) ) ) ;
2239
+ title = doc. as_ref( ) . unwrap( ) . as_slice( ) ,
2240
+ name = name. as_slice( ) ) ) ;
2231
2241
}
2232
2242
try!( write ! ( w, "</div>" ) ) ;
2233
2243
Ok ( ( ) )
0 commit comments