Skip to content

Commit 3b8a24d

Browse files
Reduce nesting in externalfiles implementation
Utilize `?` instead of and_then/map operators
1 parent 1aa0964 commit 3b8a24d

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

src/librustdoc/externalfiles.rs

+14-28
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,20 @@ impl ExternalHtml {
2525
id_map: &mut IdMap, edition: Edition, playground: &Option<Playground>)
2626
-> Option<ExternalHtml> {
2727
let codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
28-
load_external_files(in_header, diag)
29-
.and_then(|ih|
30-
load_external_files(before_content, diag)
31-
.map(|bc| (ih, bc))
32-
)
33-
.and_then(|(ih, bc)|
34-
load_external_files(md_before_content, diag)
35-
.map(|m_bc| (ih,
36-
format!("{}{}", bc, Markdown(&m_bc, &[], id_map,
37-
codes, edition, playground).to_string())))
38-
)
39-
.and_then(|(ih, bc)|
40-
load_external_files(after_content, diag)
41-
.map(|ac| (ih, bc, ac))
42-
)
43-
.and_then(|(ih, bc, ac)|
44-
load_external_files(md_after_content, diag)
45-
.map(|m_ac| (ih, bc,
46-
format!("{}{}", ac, Markdown(&m_ac, &[], id_map,
47-
codes, edition, playground).to_string())))
48-
)
49-
.map(|(ih, bc, ac)|
50-
ExternalHtml {
51-
in_header: ih,
52-
before_content: bc,
53-
after_content: ac,
54-
}
55-
)
28+
let ih = load_external_files(in_header, diag)?;
29+
let bc = load_external_files(before_content, diag)?;
30+
let m_bc = load_external_files(md_before_content, diag)?;
31+
let bc = format!("{}{}", bc, Markdown(&m_bc, &[], id_map,
32+
codes, edition, playground).to_string());
33+
let ac = load_external_files(after_content, diag)?;
34+
let m_ac = load_external_files(md_after_content, diag)?;
35+
let ac = format!("{}{}", ac, Markdown(&m_ac, &[], id_map,
36+
codes, edition, playground).to_string());
37+
Some(ExternalHtml {
38+
in_header: ih,
39+
before_content: bc,
40+
after_content: ac,
41+
})
5642
}
5743
}
5844

0 commit comments

Comments
 (0)