diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-08-31 12:27:27 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-09-07 19:31:59 -0400 |
| commit | 17bef30d0b1cc3851fb76fdd84b4d15bb629dc39 (patch) | |
| tree | dfbf336e69c1252705cd0269fd2417ab79e2575e | |
| parent | bb40d5fa498603f041dcf1092099c0b93928e442 (diff) | |
| download | rust-17bef30d0b1cc3851fb76fdd84b4d15bb629dc39.tar.gz rust-17bef30d0b1cc3851fb76fdd84b4d15bb629dc39.zip | |
Settings to function
| -rw-r--r-- | src/librustdoc/html/render.rs | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 4514a540f54..2eb2ba4e2b2 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1801,42 +1801,25 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } -#[derive(Debug)] -struct Settings<'a> { +fn settings(root_path: &str, suffix: &str) -> String { // (id, explanation, default value) - settings: Vec<(&'static str, &'static str, bool)>, - root_path: &'a str, - suffix: &'a str, -} - -impl<'a> Settings<'a> { - pub fn new(root_path: &'a str, suffix: &'a str) -> Settings<'a> { - Settings { - settings: vec![ - ("item-declarations", "Auto-hide item declarations.", true), - ("item-attributes", "Auto-hide item attributes.", true), - ("trait-implementations", "Auto-hide trait implementations documentation", - true), - ("method-docs", "Auto-hide item methods' documentation", false), - ("go-to-only-result", "Directly go to item in search if there is only one result", - false), - ("line-numbers", "Show line numbers on code examples", false), - ], - root_path, - suffix, - } - } -} - -impl<'a> fmt::Display for Settings<'a> { -fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, + let settings = [ + ("item-declarations", "Auto-hide item declarations.", true), + ("item-attributes", "Auto-hide item attributes.", true), + ("trait-implementations", "Auto-hide trait implementations documentation", + true), + ("method-docs", "Auto-hide item methods' documentation", false), + ("go-to-only-result", "Directly go to item in search if there is only one result", + false), + ("line-numbers", "Show line numbers on code examples", false), + ]; + format!( "<h1 class='fqn'>\ <span class='in-band'>Rustdoc settings</span>\ </h1>\ <div class='settings'>{}</div>\ <script src='{}settings{}.js'></script>", - self.settings.iter() + settings.iter() .map(|(id, text, enabled)| { format!("<div class='setting-line'>\ <label class='toggle'>\ @@ -1847,9 +1830,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { </div>", id, if *enabled { " checked" } else { "" }, text) }) .collect::<String>(), - self.root_path, - self.suffix) -} + root_path, + suffix) } impl Context { @@ -1924,8 +1906,6 @@ impl Context { self.shared.fs.write(&final_file, v.as_bytes())?; // Generating settings page. - let settings = Settings::new(self.shared.static_root_path.as_deref().unwrap_or("./"), - &self.shared.resource_suffix); page.title = "Rustdoc settings"; page.description = "Settings of Rustdoc"; page.root_path = "./"; @@ -1935,7 +1915,10 @@ impl Context { themes.push(PathBuf::from("settings.css")); let v = layout::render( &self.shared.layout, - &page, sidebar, |buf: &mut Buffer| buf.from_display(settings), + &page, sidebar, settings( + self.shared.static_root_path.as_deref().unwrap_or("./"), + &self.shared.resource_suffix + ), &themes); self.shared.fs.write(&settings_file, v.as_bytes())?; |
