@@ -89,9 +89,6 @@ pub struct Context {
89
89
/// Current hierarchy of components leading down to what's currently being
90
90
/// rendered
91
91
pub current : Vec < String > ,
92
- /// String representation of how to get back to the root path of the 'doc/'
93
- /// folder in terms of a relative URL.
94
- pub root_path : String ,
95
92
/// The current destination folder of where HTML artifacts should be placed.
96
93
/// This changes as the context descends into the module hierarchy.
97
94
pub dst : PathBuf ,
@@ -496,7 +493,6 @@ pub fn run(mut krate: clean::Crate,
496
493
krate = render_sources ( & dst, & mut scx, krate) ?;
497
494
let cx = Context {
498
495
current : Vec :: new ( ) ,
499
- root_path : String :: new ( ) ,
500
496
dst : dst,
501
497
render_redirect_pages : false ,
502
498
shared : Arc :: new ( scx) ,
@@ -591,7 +587,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
591
587
for & ( did, ref item) in orphan_impl_items {
592
588
if let Some ( & ( ref fqp, _) ) = paths. get ( & did) {
593
589
search_index. push ( IndexItem {
594
- ty : item_type ( item) ,
590
+ ty : item. type_ ( ) ,
595
591
name : item. name . clone ( ) . unwrap ( ) ,
596
592
path : fqp[ ..fqp. len ( ) - 1 ] . join ( "::" ) ,
597
593
desc : Escape ( & shorter ( item. doc_value ( ) ) ) . to_string ( ) ,
@@ -835,11 +831,6 @@ fn mkdir(path: &Path) -> io::Result<()> {
835
831
}
836
832
}
837
833
838
- /// Returns a documentation-level item type from the item.
839
- fn item_type ( item : & clean:: Item ) -> ItemType {
840
- ItemType :: from ( item)
841
- }
842
-
843
834
/// Takes a path to a source file and cleans the path to it. This canonicalizes
844
835
/// things like ".." to components which preserve the "top down" hierarchy of a
845
836
/// static HTML tree. Each component in the cleaned path will be passed as an
@@ -1075,7 +1066,7 @@ impl DocFolder for Cache {
1075
1066
// inserted later on when serializing the search-index.
1076
1067
if item. def_id . index != CRATE_DEF_INDEX {
1077
1068
self . search_index . push ( IndexItem {
1078
- ty : item_type ( & item) ,
1069
+ ty : item. type_ ( ) ,
1079
1070
name : s. to_string ( ) ,
1080
1071
path : path. join ( "::" ) . to_string ( ) ,
1081
1072
desc : Escape ( & shorter ( item. doc_value ( ) ) ) . to_string ( ) ,
@@ -1122,7 +1113,7 @@ impl DocFolder for Cache {
1122
1113
self . access_levels . is_public ( item. def_id )
1123
1114
{
1124
1115
self . paths . insert ( item. def_id ,
1125
- ( self . stack . clone ( ) , item_type ( & item) ) ) ;
1116
+ ( self . stack . clone ( ) , item. type_ ( ) ) ) ;
1126
1117
}
1127
1118
}
1128
1119
// link variants to their parent enum because pages aren't emitted
@@ -1135,7 +1126,7 @@ impl DocFolder for Cache {
1135
1126
1136
1127
clean:: PrimitiveItem ( ..) if item. visibility . is_some ( ) => {
1137
1128
self . paths . insert ( item. def_id , ( self . stack . clone ( ) ,
1138
- item_type ( & item) ) ) ;
1129
+ item. type_ ( ) ) ) ;
1139
1130
}
1140
1131
1141
1132
_ => { }
@@ -1230,6 +1221,12 @@ impl<'a> Cache {
1230
1221
}
1231
1222
1232
1223
impl Context {
1224
+ /// String representation of how to get back to the root path of the 'doc/'
1225
+ /// folder in terms of a relative URL.
1226
+ fn root_path ( & self ) -> String {
1227
+ repeat ( "../" ) . take ( self . current . len ( ) ) . collect :: < String > ( )
1228
+ }
1229
+
1233
1230
/// Recurse in the directory structure and change the "root path" to make
1234
1231
/// sure it always points to the top (relatively)
1235
1232
fn recurse < T , F > ( & mut self , s : String , f : F ) -> T where
@@ -1240,7 +1237,6 @@ impl Context {
1240
1237
}
1241
1238
let prev = self . dst . clone ( ) ;
1242
1239
self . dst . push ( & s) ;
1243
- self . root_path . push_str ( "../" ) ;
1244
1240
self . current . push ( s) ;
1245
1241
1246
1242
info ! ( "Recursing into {}" , self . dst. display( ) ) ;
@@ -1251,8 +1247,6 @@ impl Context {
1251
1247
1252
1248
// Go back to where we were at
1253
1249
self . dst = prev;
1254
- let len = self . root_path . len ( ) ;
1255
- self . root_path . truncate ( len - 3 ) ;
1256
1250
self . current . pop ( ) . unwrap ( ) ;
1257
1251
1258
1252
return ret;
@@ -1304,7 +1298,7 @@ impl Context {
1304
1298
title. push_str ( it. name . as_ref ( ) . unwrap ( ) ) ;
1305
1299
}
1306
1300
title. push_str ( " - Rust" ) ;
1307
- let tyname = item_type ( it ) . css_class ( ) ;
1301
+ let tyname = it . type_ ( ) . css_class ( ) ;
1308
1302
let desc = if it. is_crate ( ) {
1309
1303
format ! ( "API documentation for the Rust `{}` crate." ,
1310
1304
self . shared. layout. krate)
@@ -1315,7 +1309,7 @@ impl Context {
1315
1309
let keywords = make_item_keywords ( it) ;
1316
1310
let page = layout:: Page {
1317
1311
css_class : tyname,
1318
- root_path : & self . root_path ,
1312
+ root_path : & self . root_path ( ) ,
1319
1313
title : & title,
1320
1314
description : & desc,
1321
1315
keywords : & keywords,
@@ -1329,8 +1323,7 @@ impl Context {
1329
1323
& Item { cx : self , item : it } ,
1330
1324
self . shared . css_file_extension . is_some ( ) ) ?;
1331
1325
} else {
1332
- let mut url = repeat ( "../" ) . take ( self . current . len ( ) )
1333
- . collect :: < String > ( ) ;
1326
+ let mut url = self . root_path ( ) ;
1334
1327
if let Some ( & ( ref names, ty) ) = cache ( ) . paths . get ( & it. def_id ) {
1335
1328
for name in & names[ ..names. len ( ) - 1 ] {
1336
1329
url. push_str ( name) ;
@@ -1407,7 +1400,7 @@ impl Context {
1407
1400
// buf will be empty if the item is stripped and there is no redirect for it
1408
1401
if !buf. is_empty ( ) {
1409
1402
let name = item. name . as_ref ( ) . unwrap ( ) ;
1410
- let item_type = item_type ( & item) ;
1403
+ let item_type = item. type_ ( ) ;
1411
1404
let file_name = & item_path ( item_type, name) ;
1412
1405
let joint_dst = self . dst . join ( file_name) ;
1413
1406
try_err ! ( fs:: create_dir_all( & self . dst) , & self . dst) ;
@@ -1444,7 +1437,7 @@ impl Context {
1444
1437
for item in & m. items {
1445
1438
if maybe_ignore_item ( item) { continue }
1446
1439
1447
- let short = item_type ( item) . css_class ( ) ;
1440
+ let short = item. type_ ( ) . css_class ( ) ;
1448
1441
let myname = match item. name {
1449
1442
None => continue ,
1450
1443
Some ( ref s) => s. to_string ( ) ,
@@ -1492,7 +1485,7 @@ impl<'a> Item<'a> {
1492
1485
} ) . map ( |l| & l. 1 ) ;
1493
1486
let root = match root {
1494
1487
Some ( & Remote ( ref s) ) => s. to_string ( ) ,
1495
- Some ( & Local ) => self . cx . root_path . clone ( ) ,
1488
+ Some ( & Local ) => self . cx . root_path ( ) ,
1496
1489
None | Some ( & Unknown ) => return None ,
1497
1490
} ;
1498
1491
Some ( format ! ( "{root}/{krate}/macro.{name}.html?gotomacrosrc=1" ,
@@ -1507,7 +1500,7 @@ impl<'a> Item<'a> {
1507
1500
let path = PathBuf :: from ( & self . item . source . filename ) ;
1508
1501
self . cx . shared . local_sources . get ( & path) . map ( |path| {
1509
1502
format ! ( "{root}src/{krate}/{path}#{href}" ,
1510
- root = self . cx. root_path,
1503
+ root = self . cx. root_path( ) ,
1511
1504
krate = self . cx. shared. layout. krate,
1512
1505
path = path,
1513
1506
href = href)
@@ -1531,7 +1524,7 @@ impl<'a> Item<'a> {
1531
1524
} ;
1532
1525
let mut path = match cache. extern_locations . get ( & self . item . def_id . krate ) {
1533
1526
Some ( & ( _, Remote ( ref s) ) ) => s. to_string ( ) ,
1534
- Some ( & ( _, Local ) ) => self . cx . root_path . clone ( ) ,
1527
+ Some ( & ( _, Local ) ) => self . cx . root_path ( ) ,
1535
1528
Some ( & ( _, Unknown ) ) => return None ,
1536
1529
None => return None ,
1537
1530
} ;
@@ -1541,7 +1534,7 @@ impl<'a> Item<'a> {
1541
1534
}
1542
1535
Some ( format ! ( "{path}{file}?gotosrc={goto}" ,
1543
1536
path = path,
1544
- file = item_path( item_type ( self . item) , external_path. last( ) . unwrap( ) ) ,
1537
+ file = item_path( self . item. type_ ( ) , external_path. last( ) . unwrap( ) ) ,
1545
1538
goto = self . item. def_id. index. as_usize( ) ) )
1546
1539
}
1547
1540
}
@@ -1586,7 +1579,7 @@ impl<'a> fmt::Display for Item<'a> {
1586
1579
}
1587
1580
}
1588
1581
write ! ( fmt, "<a class='{}' href=''>{}</a>" ,
1589
- item_type ( self . item) , self . item. name. as_ref( ) . unwrap( ) ) ?;
1582
+ self . item. type_ ( ) , self . item. name. as_ref( ) . unwrap( ) ) ?;
1590
1583
1591
1584
write ! ( fmt, "</span>" ) ?; // in-band
1592
1585
write ! ( fmt, "<span class='out-of-band'>" ) ?;
@@ -1739,8 +1732,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1739
1732
}
1740
1733
1741
1734
fn cmp ( i1 : & clean:: Item , i2 : & clean:: Item , idx1 : usize , idx2 : usize ) -> Ordering {
1742
- let ty1 = item_type ( i1 ) ;
1743
- let ty2 = item_type ( i2 ) ;
1735
+ let ty1 = i1 . type_ ( ) ;
1736
+ let ty2 = i2 . type_ ( ) ;
1744
1737
if ty1 != ty2 {
1745
1738
return ( reorder ( ty1) , idx1) . cmp ( & ( reorder ( ty2) , idx2) )
1746
1739
}
@@ -1764,7 +1757,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1764
1757
continue ;
1765
1758
}
1766
1759
1767
- let myty = Some ( item_type ( myitem) ) ;
1760
+ let myty = Some ( myitem. type_ ( ) ) ;
1768
1761
if curty == Some ( ItemType :: ExternCrate ) && myty == Some ( ItemType :: Import ) {
1769
1762
// Put `extern crate` and `use` re-exports in the same section.
1770
1763
curty = myty;
@@ -1851,9 +1844,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1851
1844
name = * myitem. name. as_ref( ) . unwrap( ) ,
1852
1845
stab_docs = stab_docs,
1853
1846
docs = shorter( Some ( & Markdown ( doc_value) . to_string( ) ) ) ,
1854
- class = item_type ( myitem) ,
1847
+ class = myitem. type_ ( ) ,
1855
1848
stab = myitem. stability_class( ) ,
1856
- href = item_path( item_type ( myitem) , myitem. name. as_ref( ) . unwrap( ) ) ,
1849
+ href = item_path( myitem. type_ ( ) , myitem. name. as_ref( ) . unwrap( ) ) ,
1857
1850
title = full_path( cx, myitem) ) ?;
1858
1851
}
1859
1852
}
@@ -2059,7 +2052,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2059
2052
fn trait_item ( w : & mut fmt:: Formatter , cx : & Context , m : & clean:: Item , t : & clean:: Item )
2060
2053
-> fmt:: Result {
2061
2054
let name = m. name . as_ref ( ) . unwrap ( ) ;
2062
- let item_type = item_type ( m ) ;
2055
+ let item_type = m . type_ ( ) ;
2063
2056
let id = derive_id ( format ! ( "{}.{}" , item_type, name) ) ;
2064
2057
let ns_id = derive_id ( format ! ( "{}.{}" , name, item_type. name_space( ) ) ) ;
2065
2058
write ! ( w, "<h3 id='{id}' class='method stab {stab}'>\
@@ -2145,7 +2138,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
2145
2138
let ( ref path, _) = cache. external_paths[ & it. def_id] ;
2146
2139
path[ ..path. len( ) - 1 ] . join( "/" )
2147
2140
} ,
2148
- ty = item_type ( it ) . css_class( ) ,
2141
+ ty = it . type_ ( ) . css_class( ) ,
2149
2142
name = * it. name. as_ref( ) . unwrap( ) ) ?;
2150
2143
Ok ( ( ) )
2151
2144
}
@@ -2154,7 +2147,7 @@ fn naive_assoc_href(it: &clean::Item, link: AssocItemLink) -> String {
2154
2147
use html:: item_type:: ItemType :: * ;
2155
2148
2156
2149
let name = it. name . as_ref ( ) . unwrap ( ) ;
2157
- let ty = match item_type ( it ) {
2150
+ let ty = match it . type_ ( ) {
2158
2151
Typedef | AssociatedType => AssociatedType ,
2159
2152
s@_ => s,
2160
2153
} ;
@@ -2232,7 +2225,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
2232
2225
link : AssocItemLink )
2233
2226
-> fmt:: Result {
2234
2227
let name = meth. name . as_ref ( ) . unwrap ( ) ;
2235
- let anchor = format ! ( "#{}.{}" , item_type ( meth) , name) ;
2228
+ let anchor = format ! ( "#{}.{}" , meth. type_ ( ) , name) ;
2236
2229
let href = match link {
2237
2230
AssocItemLink :: Anchor ( Some ( ref id) ) => format ! ( "#{}" , id) ,
2238
2231
AssocItemLink :: Anchor ( None ) => anchor,
@@ -2740,7 +2733,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
2740
2733
link : AssocItemLink , render_mode : RenderMode ,
2741
2734
is_default_item : bool , outer_version : Option < & str > ,
2742
2735
trait_ : Option < & clean:: Trait > ) -> fmt:: Result {
2743
- let item_type = item_type ( item) ;
2736
+ let item_type = item. type_ ( ) ;
2744
2737
let name = item. name . as_ref ( ) . unwrap ( ) ;
2745
2738
2746
2739
let render_method_item: bool = match render_mode {
@@ -2918,7 +2911,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
2918
2911
write ! ( fmt, "::<wbr>" ) ?;
2919
2912
}
2920
2913
write ! ( fmt, "<a href='{}index.html'>{}</a>" ,
2921
- & cx. root_path[ ..( cx. current. len( ) - i - 1 ) * 3 ] ,
2914
+ & cx. root_path( ) [ ..( cx. current. len( ) - i - 1 ) * 3 ] ,
2922
2915
* name) ?;
2923
2916
}
2924
2917
write ! ( fmt, "</p>" ) ?;
@@ -2932,7 +2925,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
2932
2925
relpath: '{path}'\
2933
2926
}};</script>",
2934
2927
name = it. name. as_ref( ) . map( |x| & x[ ..] ) . unwrap_or( "" ) ,
2935
- ty = item_type ( it ) . css_class( ) ,
2928
+ ty = it . type_ ( ) . css_class( ) ,
2936
2929
path = relpath) ?;
2937
2930
if parentlen == 0 {
2938
2931
// there is no sidebar-items.js beyond the crate root path
0 commit comments