Skip to content

Commit 295f5dd

Browse files
committed
use early return to make function easier to read
1 parent 735e7c6 commit 295f5dd

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/web/rustdoc.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,29 +285,29 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
285285
///
286286
/// Returns a path that can be appended to `/crate/version/` to create a complete URL.
287287
fn path_for_version(req_path: &[&str], target_name: &str, conn: &Connection) -> String {
288+
// Simple case: page exists in the latest version, so just change the version number
288289
if File::from_path(&conn, &req_path.join("/")).is_some() {
289290
// NOTE: this adds 'index.html' if it wasn't there before
290-
req_path[3..].join("/")
291-
} else {
292-
// this page doesn't exist in the latest version
293-
let search_item = if *req_path.last().unwrap() == "index.html" {
294-
// this is a module
295-
req_path[req_path.len() - 2]
296-
} else {
297-
// this is an item
298-
req_path.last().unwrap().split('.').nth(1)
299-
.expect("paths should be of the form <class>.<name>.html")
300-
};
301-
// check if req_path[3] is the platform choice or the name of the crate
302-
let concat_path;
303-
let crate_root = if req_path[3] != target_name {
304-
concat_path = format!("{}/{}", req_path[3], req_path[4]);
305-
&concat_path
306-
} else {
307-
req_path[3]
308-
};
309-
format!("{}/?search={}", crate_root, search_item)
291+
return req_path[3..].join("/");
310292
}
293+
// this page doesn't exist in the latest version
294+
let search_item = if *req_path.last().unwrap() == "index.html" {
295+
// this is a module
296+
req_path[req_path.len() - 2]
297+
} else {
298+
// this is an item
299+
req_path.last().unwrap().split('.').nth(1)
300+
.expect("paths should be of the form <class>.<name>.html")
301+
};
302+
// check if req_path[3] is the platform choice or the name of the crate
303+
let concat_path;
304+
let crate_root = if req_path[3] != target_name {
305+
concat_path = format!("{}/{}", req_path[3], req_path[4]);
306+
&concat_path
307+
} else {
308+
req_path[3]
309+
};
310+
format!("{}/?search={}", crate_root, search_item)
311311
}
312312

313313
pub fn badge_handler(req: &mut Request) -> IronResult<Response> {

0 commit comments

Comments
 (0)