Skip to content

Commit 17bef30

Browse files
Settings to function
1 parent bb40d5f commit 17bef30

File tree

1 file changed

+19
-36
lines changed

1 file changed

+19
-36
lines changed

src/librustdoc/html/render.rs

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,42 +1801,25 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18011801
}
18021802
}
18031803

1804-
#[derive(Debug)]
1805-
struct Settings<'a> {
1804+
fn settings(root_path: &str, suffix: &str) -> String {
18061805
// (id, explanation, default value)
1807-
settings: Vec<(&'static str, &'static str, bool)>,
1808-
root_path: &'a str,
1809-
suffix: &'a str,
1810-
}
1811-
1812-
impl<'a> Settings<'a> {
1813-
pub fn new(root_path: &'a str, suffix: &'a str) -> Settings<'a> {
1814-
Settings {
1815-
settings: vec![
1816-
("item-declarations", "Auto-hide item declarations.", true),
1817-
("item-attributes", "Auto-hide item attributes.", true),
1818-
("trait-implementations", "Auto-hide trait implementations documentation",
1819-
true),
1820-
("method-docs", "Auto-hide item methods' documentation", false),
1821-
("go-to-only-result", "Directly go to item in search if there is only one result",
1822-
false),
1823-
("line-numbers", "Show line numbers on code examples", false),
1824-
],
1825-
root_path,
1826-
suffix,
1827-
}
1828-
}
1829-
}
1830-
1831-
impl<'a> fmt::Display for Settings<'a> {
1832-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1833-
write!(f,
1806+
let settings = [
1807+
("item-declarations", "Auto-hide item declarations.", true),
1808+
("item-attributes", "Auto-hide item attributes.", true),
1809+
("trait-implementations", "Auto-hide trait implementations documentation",
1810+
true),
1811+
("method-docs", "Auto-hide item methods' documentation", false),
1812+
("go-to-only-result", "Directly go to item in search if there is only one result",
1813+
false),
1814+
("line-numbers", "Show line numbers on code examples", false),
1815+
];
1816+
format!(
18341817
"<h1 class='fqn'>\
18351818
<span class='in-band'>Rustdoc settings</span>\
18361819
</h1>\
18371820
<div class='settings'>{}</div>\
18381821
<script src='{}settings{}.js'></script>",
1839-
self.settings.iter()
1822+
settings.iter()
18401823
.map(|(id, text, enabled)| {
18411824
format!("<div class='setting-line'>\
18421825
<label class='toggle'>\
@@ -1847,9 +1830,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18471830
</div>", id, if *enabled { " checked" } else { "" }, text)
18481831
})
18491832
.collect::<String>(),
1850-
self.root_path,
1851-
self.suffix)
1852-
}
1833+
root_path,
1834+
suffix)
18531835
}
18541836

18551837
impl Context {
@@ -1924,8 +1906,6 @@ impl Context {
19241906
self.shared.fs.write(&final_file, v.as_bytes())?;
19251907

19261908
// Generating settings page.
1927-
let settings = Settings::new(self.shared.static_root_path.as_deref().unwrap_or("./"),
1928-
&self.shared.resource_suffix);
19291909
page.title = "Rustdoc settings";
19301910
page.description = "Settings of Rustdoc";
19311911
page.root_path = "./";
@@ -1935,7 +1915,10 @@ impl Context {
19351915
themes.push(PathBuf::from("settings.css"));
19361916
let v = layout::render(
19371917
&self.shared.layout,
1938-
&page, sidebar, |buf: &mut Buffer| buf.from_display(settings),
1918+
&page, sidebar, settings(
1919+
self.shared.static_root_path.as_deref().unwrap_or("./"),
1920+
&self.shared.resource_suffix
1921+
),
19391922
&themes);
19401923
self.shared.fs.write(&settings_file, v.as_bytes())?;
19411924

0 commit comments

Comments
 (0)