@@ -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) ,
@@ -1225,6 +1221,12 @@ impl<'a> Cache {
1225
1221
}
1226
1222
1227
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
+
1228
1230
/// Recurse in the directory structure and change the "root path" to make
1229
1231
/// sure it always points to the top (relatively)
1230
1232
fn recurse < T , F > ( & mut self , s : String , f : F ) -> T where
@@ -1235,7 +1237,6 @@ impl Context {
1235
1237
}
1236
1238
let prev = self . dst . clone ( ) ;
1237
1239
self . dst . push ( & s) ;
1238
- self . root_path . push_str ( "../" ) ;
1239
1240
self . current . push ( s) ;
1240
1241
1241
1242
info ! ( "Recursing into {}" , self . dst. display( ) ) ;
@@ -1246,8 +1247,6 @@ impl Context {
1246
1247
1247
1248
// Go back to where we were at
1248
1249
self . dst = prev;
1249
- let len = self . root_path . len ( ) ;
1250
- self . root_path . truncate ( len - 3 ) ;
1251
1250
self . current . pop ( ) . unwrap ( ) ;
1252
1251
1253
1252
return ret;
@@ -1310,7 +1309,7 @@ impl Context {
1310
1309
let keywords = make_item_keywords ( it) ;
1311
1310
let page = layout:: Page {
1312
1311
css_class : tyname,
1313
- root_path : & self . root_path ,
1312
+ root_path : & self . root_path ( ) ,
1314
1313
title : & title,
1315
1314
description : & desc,
1316
1315
keywords : & keywords,
@@ -1324,8 +1323,7 @@ impl Context {
1324
1323
& Item { cx : self , item : it } ,
1325
1324
self . shared . css_file_extension . is_some ( ) ) ?;
1326
1325
} else {
1327
- let mut url = repeat ( "../" ) . take ( self . current . len ( ) )
1328
- . collect :: < String > ( ) ;
1326
+ let mut url = self . root_path ( ) ;
1329
1327
if let Some ( & ( ref names, ty) ) = cache ( ) . paths . get ( & it. def_id ) {
1330
1328
for name in & names[ ..names. len ( ) - 1 ] {
1331
1329
url. push_str ( name) ;
@@ -1487,7 +1485,7 @@ impl<'a> Item<'a> {
1487
1485
} ) . map ( |l| & l. 1 ) ;
1488
1486
let root = match root {
1489
1487
Some ( & Remote ( ref s) ) => s. to_string ( ) ,
1490
- Some ( & Local ) => self . cx . root_path . clone ( ) ,
1488
+ Some ( & Local ) => self . cx . root_path ( ) ,
1491
1489
None | Some ( & Unknown ) => return None ,
1492
1490
} ;
1493
1491
Some ( format ! ( "{root}/{krate}/macro.{name}.html?gotomacrosrc=1" ,
@@ -1502,7 +1500,7 @@ impl<'a> Item<'a> {
1502
1500
let path = PathBuf :: from ( & self . item . source . filename ) ;
1503
1501
self . cx . shared . local_sources . get ( & path) . map ( |path| {
1504
1502
format ! ( "{root}src/{krate}/{path}#{href}" ,
1505
- root = self . cx. root_path,
1503
+ root = self . cx. root_path( ) ,
1506
1504
krate = self . cx. shared. layout. krate,
1507
1505
path = path,
1508
1506
href = href)
@@ -1526,7 +1524,7 @@ impl<'a> Item<'a> {
1526
1524
} ;
1527
1525
let mut path = match cache. extern_locations . get ( & self . item . def_id . krate ) {
1528
1526
Some ( & ( _, Remote ( ref s) ) ) => s. to_string ( ) ,
1529
- Some ( & ( _, Local ) ) => self . cx . root_path . clone ( ) ,
1527
+ Some ( & ( _, Local ) ) => self . cx . root_path ( ) ,
1530
1528
Some ( & ( _, Unknown ) ) => return None ,
1531
1529
None => return None ,
1532
1530
} ;
@@ -2913,7 +2911,7 @@ impl<'a> fmt::Display for Sidebar<'a> {
2913
2911
write ! ( fmt, "::<wbr>" ) ?;
2914
2912
}
2915
2913
write ! ( fmt, "<a href='{}index.html'>{}</a>" ,
2916
- & cx. root_path[ ..( cx. current. len( ) - i - 1 ) * 3 ] ,
2914
+ & cx. root_path( ) [ ..( cx. current. len( ) - i - 1 ) * 3 ] ,
2917
2915
* name) ?;
2918
2916
}
2919
2917
write ! ( fmt, "</p>" ) ?;
0 commit comments