@@ -381,12 +381,6 @@ pub struct RenderInfo {
381
381
// Helper structs for rendering items/sidebars and carrying along contextual
382
382
// information
383
383
384
- #[ derive( Copy , Clone ) ]
385
- struct Item < ' a > {
386
- cx : & ' a Context ,
387
- item : & ' a clean:: Item ,
388
- }
389
-
390
384
/// Struct representing one entry in the JS search index. These are all emitted
391
385
/// by hand to a large JS file at the end of cache-creation.
392
386
#[ derive( Debug ) ]
@@ -1974,7 +1968,7 @@ impl Context {
1974
1968
if !self . render_redirect_pages {
1975
1969
layout:: render ( & self . shared . layout , & page,
1976
1970
|buf : & mut _ | print_sidebar ( self , it, buf) ,
1977
- |buf : & mut Buffer | buf . from_display ( Item { cx : self , item : it } ) ,
1971
+ |buf : & mut _ | print_item ( self , it , buf ) ,
1978
1972
& self . shared . themes )
1979
1973
} else {
1980
1974
let mut url = self . root_path ( ) ;
@@ -2115,7 +2109,7 @@ impl Context {
2115
2109
}
2116
2110
}
2117
2111
2118
- impl < ' a > Item < ' a > {
2112
+ impl Context {
2119
2113
/// Generates a url appropriate for an `href` attribute back to the source of
2120
2114
/// this item.
2121
2115
///
@@ -2125,26 +2119,26 @@ impl<'a> Item<'a> {
2125
2119
/// If `None` is returned, then a source link couldn't be generated. This
2126
2120
/// may happen, for example, with externally inlined items where the source
2127
2121
/// of their crate documentation isn't known.
2128
- fn src_href ( & self ) -> Option < String > {
2129
- let mut root = self . cx . root_path ( ) ;
2122
+ fn src_href ( & self , item : & clean :: Item ) -> Option < String > {
2123
+ let mut root = self . root_path ( ) ;
2130
2124
2131
2125
let cache = cache ( ) ;
2132
2126
let mut path = String :: new ( ) ;
2133
2127
2134
2128
// We can safely ignore macros from other libraries
2135
- let file = match self . item . source . filename {
2129
+ let file = match item. source . filename {
2136
2130
FileName :: Real ( ref path) => path,
2137
2131
_ => return None ,
2138
2132
} ;
2139
2133
2140
- let ( krate, path) = if self . item . def_id . is_local ( ) {
2141
- if let Some ( path) = self . cx . shared . local_sources . get ( file) {
2142
- ( & self . cx . shared . layout . krate , path)
2134
+ let ( krate, path) = if item. def_id . is_local ( ) {
2135
+ if let Some ( path) = self . shared . local_sources . get ( file) {
2136
+ ( & self . shared . layout . krate , path)
2143
2137
} else {
2144
2138
return None ;
2145
2139
}
2146
2140
} else {
2147
- let ( krate, src_root) = match * cache. extern_locations . get ( & self . item . def_id . krate ) ? {
2141
+ let ( krate, src_root) = match * cache. extern_locations . get ( & item. def_id . krate ) ? {
2148
2142
( ref name, ref src, Local ) => ( name, src) ,
2149
2143
( ref name, ref src, Remote ( ref s) ) => {
2150
2144
root = s. to_string ( ) ;
@@ -2164,10 +2158,10 @@ impl<'a> Item<'a> {
2164
2158
( krate, & path)
2165
2159
} ;
2166
2160
2167
- let lines = if self . item . source . loline == self . item . source . hiline {
2168
- self . item . source . loline . to_string ( )
2161
+ let lines = if item. source . loline == item. source . hiline {
2162
+ item. source . loline . to_string ( )
2169
2163
} else {
2170
- format ! ( "{}-{}" , self . item. source. loline, self . item. source. hiline)
2164
+ format ! ( "{}-{}" , item. source. loline, item. source. hiline)
2171
2165
} ;
2172
2166
Some ( format ! ( "{root}src/{krate}/{path}#{lines}" ,
2173
2167
root = Escape ( & root) ,
@@ -2185,108 +2179,109 @@ where F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result {
2185
2179
write ! ( w, "</div>" )
2186
2180
}
2187
2181
2188
- impl < ' a > fmt:: Display for Item < ' a > {
2189
- fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2190
- debug_assert ! ( !self . item. is_stripped( ) ) ;
2182
+ fn print_item ( cx : & Context , item : & clean:: Item , buf : & mut Buffer ) {
2183
+ debug_assert ! ( !item. is_stripped( ) ) ;
2191
2184
// Write the breadcrumb trail header for the top
2192
- write ! ( fmt , "<h1 class='fqn'><span class='out-of-band'>" ) ? ;
2193
- if let Some ( version) = self . item . stable_since ( ) {
2194
- write ! ( fmt , "<span class='since' title='Stable since Rust version {0}'>{0}</span>" ,
2195
- version) ? ;
2185
+ write ! ( buf , "<h1 class='fqn'><span class='out-of-band'>" ) ;
2186
+ if let Some ( version) = item. stable_since ( ) {
2187
+ write ! ( buf , "<span class='since' title='Stable since Rust version {0}'>{0}</span>" ,
2188
+ version) ;
2196
2189
}
2197
- write ! ( fmt ,
2190
+ write ! ( buf ,
2198
2191
"<span id='render-detail'>\
2199
2192
<a id=\" toggle-all-docs\" href=\" javascript:void(0)\" \
2200
2193
title=\" collapse all docs\" >\
2201
2194
[<span class='inner'>−</span>]\
2202
2195
</a>\
2203
- </span>") ? ;
2196
+ </span>") ;
2204
2197
2205
2198
// Write `src` tag
2206
2199
//
2207
2200
// When this item is part of a `pub use` in a downstream crate, the
2208
2201
// [src] link in the downstream documentation will actually come back to
2209
2202
// this page, and this link will be auto-clicked. The `id` attribute is
2210
2203
// used to find the link to auto-click.
2211
- if self . cx . shared . include_sources && !self . item . is_primitive ( ) {
2212
- if let Some ( l) = self . src_href ( ) {
2213
- write ! ( fmt , "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
2214
- l, "goto source code" ) ? ;
2204
+ if cx. shared . include_sources && !item. is_primitive ( ) {
2205
+ if let Some ( l) = cx . src_href ( item ) {
2206
+ write ! ( buf , "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
2207
+ l, "goto source code" ) ;
2215
2208
}
2216
2209
}
2217
2210
2218
- write ! ( fmt , "</span>" ) ? ; // out-of-band
2219
- write ! ( fmt , "<span class='in-band'>" ) ? ;
2220
- match self . item . inner {
2211
+ write ! ( buf , "</span>" ) ; // out-of-band
2212
+ write ! ( buf , "<span class='in-band'>" ) ;
2213
+ let name = match item. inner {
2221
2214
clean:: ModuleItem ( ref m) => if m. is_crate {
2222
- write ! ( fmt , "Crate " ) ? ;
2215
+ "Crate "
2223
2216
} else {
2224
- write ! ( fmt , "Module " ) ? ;
2217
+ "Module "
2225
2218
} ,
2226
- clean:: FunctionItem ( ..) | clean:: ForeignFunctionItem ( ..) => write ! ( fmt , "Function " ) ? ,
2227
- clean:: TraitItem ( ..) => write ! ( fmt , "Trait " ) ? ,
2228
- clean:: StructItem ( ..) => write ! ( fmt , "Struct " ) ? ,
2229
- clean:: UnionItem ( ..) => write ! ( fmt , "Union " ) ? ,
2230
- clean:: EnumItem ( ..) => write ! ( fmt , "Enum " ) ? ,
2231
- clean:: TypedefItem ( ..) => write ! ( fmt , "Type Definition " ) ? ,
2232
- clean:: MacroItem ( ..) => write ! ( fmt , "Macro " ) ? ,
2219
+ clean:: FunctionItem ( ..) | clean:: ForeignFunctionItem ( ..) => "Function " ,
2220
+ clean:: TraitItem ( ..) => "Trait " ,
2221
+ clean:: StructItem ( ..) => "Struct " ,
2222
+ clean:: UnionItem ( ..) => "Union " ,
2223
+ clean:: EnumItem ( ..) => "Enum " ,
2224
+ clean:: TypedefItem ( ..) => "Type Definition " ,
2225
+ clean:: MacroItem ( ..) => "Macro " ,
2233
2226
clean:: ProcMacroItem ( ref mac) => match mac. kind {
2234
- MacroKind :: Bang => write ! ( fmt , "Macro " ) ? ,
2235
- MacroKind :: Attr => write ! ( fmt , "Attribute Macro " ) ? ,
2236
- MacroKind :: Derive => write ! ( fmt , "Derive Macro " ) ? ,
2237
- }
2238
- clean:: PrimitiveItem ( ..) => write ! ( fmt , "Primitive Type " ) ? ,
2239
- clean:: StaticItem ( ..) | clean:: ForeignStaticItem ( ..) => write ! ( fmt , "Static " ) ? ,
2240
- clean:: ConstantItem ( ..) => write ! ( fmt , "Constant " ) ? ,
2241
- clean:: ForeignTypeItem => write ! ( fmt , "Foreign Type " ) ? ,
2242
- clean:: KeywordItem ( ..) => write ! ( fmt , "Keyword " ) ? ,
2243
- clean:: OpaqueTyItem ( ..) => write ! ( fmt , "Opaque Type " ) ? ,
2244
- clean:: TraitAliasItem ( ..) => write ! ( fmt , "Trait Alias " ) ? ,
2227
+ MacroKind :: Bang => "Macro " ,
2228
+ MacroKind :: Attr => "Attribute Macro " ,
2229
+ MacroKind :: Derive => "Derive Macro " ,
2230
+ }
2231
+ clean:: PrimitiveItem ( ..) => "Primitive Type " ,
2232
+ clean:: StaticItem ( ..) | clean:: ForeignStaticItem ( ..) => "Static " ,
2233
+ clean:: ConstantItem ( ..) => "Constant " ,
2234
+ clean:: ForeignTypeItem => "Foreign Type " ,
2235
+ clean:: KeywordItem ( ..) => "Keyword " ,
2236
+ clean:: OpaqueTyItem ( ..) => "Opaque Type " ,
2237
+ clean:: TraitAliasItem ( ..) => "Trait Alias " ,
2245
2238
_ => {
2246
2239
// We don't generate pages for any other type.
2247
2240
unreachable ! ( ) ;
2248
2241
}
2249
- }
2250
- if !self . item . is_primitive ( ) && !self . item . is_keyword ( ) {
2251
- let cur = & self . cx . current ;
2252
- let amt = if self . item . is_mod ( ) { cur. len ( ) - 1 } else { cur. len ( ) } ;
2242
+ } ;
2243
+ buf. write_str ( name) ;
2244
+ if !item. is_primitive ( ) && !item. is_keyword ( ) {
2245
+ let cur = & cx. current ;
2246
+ let amt = if item. is_mod ( ) { cur. len ( ) - 1 } else { cur. len ( ) } ;
2253
2247
for ( i, component) in cur. iter ( ) . enumerate ( ) . take ( amt) {
2254
- write ! ( fmt , "<a href='{}index.html'>{}</a>::<wbr>" ,
2248
+ write ! ( buf , "<a href='{}index.html'>{}</a>::<wbr>" ,
2255
2249
"../" . repeat( cur. len( ) - i - 1 ) ,
2256
- component) ? ;
2250
+ component) ;
2257
2251
}
2258
2252
}
2259
- write ! ( fmt , "<a class=\" {}\" href=''>{}</a>" ,
2260
- self . item. type_( ) , self . item. name. as_ref( ) . unwrap( ) ) ? ;
2253
+ write ! ( buf , "<a class=\" {}\" href=''>{}</a>" ,
2254
+ item. type_( ) , item. name. as_ref( ) . unwrap( ) ) ;
2261
2255
2262
- write ! ( fmt , "</span></h1>" ) ? ; // in-band
2256
+ write ! ( buf , "</span></h1>" ) ; // in-band
2263
2257
2264
- match self . item . inner {
2258
+ buf. with_formatter ( |fmt| {
2259
+ match item. inner {
2265
2260
clean:: ModuleItem ( ref m) =>
2266
- item_module ( fmt, self . cx , self . item , & m. items ) ,
2261
+ item_module ( fmt, cx, item, & m. items ) ,
2267
2262
clean:: FunctionItem ( ref f) | clean:: ForeignFunctionItem ( ref f) =>
2268
- item_function ( fmt, self . cx , self . item , f) ,
2269
- clean:: TraitItem ( ref t) => item_trait ( fmt, self . cx , self . item , t) ,
2270
- clean:: StructItem ( ref s) => item_struct ( fmt, self . cx , self . item , s) ,
2271
- clean:: UnionItem ( ref s) => item_union ( fmt, self . cx , self . item , s) ,
2272
- clean:: EnumItem ( ref e) => item_enum ( fmt, self . cx , self . item , e) ,
2273
- clean:: TypedefItem ( ref t, _) => item_typedef ( fmt, self . cx , self . item , t) ,
2274
- clean:: MacroItem ( ref m) => item_macro ( fmt, self . cx , self . item , m) ,
2275
- clean:: ProcMacroItem ( ref m) => item_proc_macro ( fmt, self . cx , self . item , m) ,
2276
- clean:: PrimitiveItem ( ref p) => item_primitive ( fmt, self . cx , self . item , p) ,
2263
+ item_function ( fmt, cx, item, f) ,
2264
+ clean:: TraitItem ( ref t) => item_trait ( fmt, cx, item, t) ,
2265
+ clean:: StructItem ( ref s) => item_struct ( fmt, cx, item, s) ,
2266
+ clean:: UnionItem ( ref s) => item_union ( fmt, cx, item, s) ,
2267
+ clean:: EnumItem ( ref e) => item_enum ( fmt, cx, item, e) ,
2268
+ clean:: TypedefItem ( ref t, _) => item_typedef ( fmt, cx, item, t) ,
2269
+ clean:: MacroItem ( ref m) => item_macro ( fmt, cx, item, m) ,
2270
+ clean:: ProcMacroItem ( ref m) => item_proc_macro ( fmt, cx, item, m) ,
2271
+ clean:: PrimitiveItem ( ref p) => item_primitive ( fmt, cx, item, p) ,
2277
2272
clean:: StaticItem ( ref i) | clean:: ForeignStaticItem ( ref i) =>
2278
- item_static ( fmt, self . cx , self . item , i) ,
2279
- clean:: ConstantItem ( ref c) => item_constant ( fmt, self . cx , self . item , c) ,
2280
- clean:: ForeignTypeItem => item_foreign_type ( fmt, self . cx , self . item ) ,
2281
- clean:: KeywordItem ( ref k) => item_keyword ( fmt, self . cx , self . item , k) ,
2282
- clean:: OpaqueTyItem ( ref e, _) => item_opaque_ty ( fmt, self . cx , self . item , e) ,
2283
- clean:: TraitAliasItem ( ref ta) => item_trait_alias ( fmt, self . cx , self . item , ta) ,
2273
+ item_static ( fmt, cx, item, i) ,
2274
+ clean:: ConstantItem ( ref c) => item_constant ( fmt, cx, item, c) ,
2275
+ clean:: ForeignTypeItem => item_foreign_type ( fmt, cx, item) ,
2276
+ clean:: KeywordItem ( ref k) => item_keyword ( fmt, cx, item, k) ,
2277
+ clean:: OpaqueTyItem ( ref e, _) => item_opaque_ty ( fmt, cx, item, e) ,
2278
+ clean:: TraitAliasItem ( ref ta) => item_trait_alias ( fmt, cx, item, ta) ,
2284
2279
_ => {
2285
2280
// We don't generate pages for any other type.
2286
2281
unreachable ! ( ) ;
2287
2282
}
2288
2283
}
2289
- }
2284
+ } )
2290
2285
}
2291
2286
2292
2287
fn item_path ( ty : ItemType , name : & str ) -> String {
@@ -4004,7 +3999,7 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
4004
3999
write ! ( w, "<a href='#{}' class='anchor'></a>" , id) ?;
4005
4000
let since = i. impl_item . stability . as_ref ( ) . map ( |s| & s. since [ ..] ) ;
4006
4001
render_stability_since_raw ( w, since, outer_version) ?;
4007
- if let Some ( l) = ( Item { item : & i. impl_item , cx : cx } ) . src_href ( ) {
4002
+ if let Some ( l) = cx . src_href ( & i. impl_item ) {
4008
4003
write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
4009
4004
l, "goto source code" ) ?;
4010
4005
}
@@ -4050,7 +4045,7 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
4050
4045
render_assoc_item ( w, item, link. anchor ( & id) , ItemType :: Impl ) ?;
4051
4046
write ! ( w, "</code>" ) ?;
4052
4047
render_stability_since_raw ( w, item. stable_since ( ) , outer_version) ?;
4053
- if let Some ( l) = ( Item { cx , item } ) . src_href ( ) {
4048
+ if let Some ( l) = cx . src_href ( item ) {
4054
4049
write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
4055
4050
l, "goto source code" ) ?;
4056
4051
}
@@ -4073,7 +4068,7 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
4073
4068
assoc_const ( w, item, ty, default. as_ref ( ) , link. anchor ( & id) , "" ) ?;
4074
4069
write ! ( w, "</code>" ) ?;
4075
4070
render_stability_since_raw ( w, item. stable_since ( ) , outer_version) ?;
4076
- if let Some ( l) = ( Item { cx , item } ) . src_href ( ) {
4071
+ if let Some ( l) = cx . src_href ( item ) {
4077
4072
write ! ( w, "<a class='srclink' href='{}' title='{}'>[src]</a>" ,
4078
4073
l, "goto source code" ) ?;
4079
4074
}
0 commit comments