@@ -66,6 +66,10 @@ use html::markdown::Markdown;
6666use html:: markdown;
6767use stability_summary;
6868
69+ /// A pair of name and its optional document.
70+ #[ deriving( Clone , Eq , Ord , PartialEq , PartialOrd ) ]
71+ pub struct NameDoc ( String , Option < String > ) ;
72+
6973/// Major driving force in all rustdoc rendering. This contains information
7074/// about where in the tree-like hierarchy rendering is occurring and controls
7175/// how the current page is being rendered.
@@ -95,7 +99,7 @@ pub struct Context {
9599 /// functions), and the value is the list of containers belonging to this
96100 /// header. This map will change depending on the surrounding context of the
97101 /// page.
98- pub sidebar : HashMap < String , Vec < String > > ,
102+ pub sidebar : HashMap < String , Vec < NameDoc > > ,
99103 /// This flag indicates whether [src] links should be generated or not. If
100104 /// the source files are present in the html rendering, then this will be
101105 /// `true`.
@@ -1245,7 +1249,7 @@ impl Context {
12451249 }
12461250 }
12471251
1248- fn build_sidebar ( & self , m : & clean:: Module ) -> HashMap < String , Vec < String > > {
1252+ fn build_sidebar ( & self , m : & clean:: Module ) -> HashMap < String , Vec < NameDoc > > {
12491253 let mut map = HashMap :: new ( ) ;
12501254 for item in m. items . iter ( ) {
12511255 if self . ignore_private_item ( item) { continue }
@@ -1262,7 +1266,7 @@ impl Context {
12621266 let short = short. to_string ( ) ;
12631267 let v = map. entry ( short) . get ( ) . unwrap_or_else (
12641268 |vacant_entry| vacant_entry. insert ( Vec :: with_capacity ( 1 ) ) ) ;
1265- v. push ( myname) ;
1269+ v. push ( NameDoc ( myname, Some ( shorter_line ( item . doc_value ( ) ) ) ) ) ;
12661270 }
12671271
12681272 for ( _, items) in map. iter_mut ( ) {
@@ -1476,6 +1480,11 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str {
14761480 }
14771481}
14781482
1483+ #[ inline]
1484+ fn shorter_line ( s : Option < & str > ) -> String {
1485+ shorter ( s) . replace ( "\n " , " " )
1486+ }
1487+
14791488fn document ( w : & mut fmt:: Formatter , item : & clean:: Item ) -> fmt:: Result {
14801489 match item. doc_value ( ) {
14811490 Some ( s) => {
@@ -2213,21 +2222,22 @@ impl<'a> fmt::String for Sidebar<'a> {
22132222 None => return Ok ( ( ) )
22142223 } ;
22152224 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 ( ) {
22172226 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 &&
22192228 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>",
22222231 ty = short,
22232232 class = class,
22242233 href = if curty == "mod" { "../" } else { "" } ,
22252234 path = if short == "mod" {
2226- format!( "{}/index.html" , item . as_slice( ) )
2235+ format!( "{}/index.html" , name . as_slice( ) )
22272236 } else {
2228- format!( "{}.{}.html" , short, item . as_slice( ) )
2237+ format!( "{}.{}.html" , short, name . as_slice( ) )
22292238 } ,
2230- name = item. as_slice( ) ) ) ;
2239+ title = doc. as_ref( ) . unwrap( ) . as_slice( ) ,
2240+ name = name. as_slice( ) ) ) ;
22312241 }
22322242 try!( write ! ( w, "</div>" ) ) ;
22332243 Ok ( ( ) )
0 commit comments