From f4a15ae3b248bf91f10f6e5d031ca84dc1942e19 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 31 Aug 2019 11:22:51 -0400 Subject: Implement Print for FnOnce(&mut Buffer) This means that callers can pass in a closure like `|buf| some_function(..., &mut buf)` and pass in arbitrary arguments to that function without complicating the trait definition. We also keep the impl for str and String, since it's useful to be able to just pass in "" or format!("{}"...) results in some cases. This changes Print's definition to take self, instead of &self, because otherwise FnOnce cannot be called directly. We could instead take FnMut or even Fn, but that seems like it'd merely complicate matters -- most of the time, the FnOnce does not constrain us at all anyway. If it does, a custom Print impl for &'_ SomeStruct is not all that painful. --- src/librustdoc/html/render.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/librustdoc/html/render.rs') diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 40e7081c57c..fc7038f8bda 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1174,7 +1174,7 @@ themePicker.onblur = handleThemeButtonsBlur; }) .collect::()); let v = layout::render(&cx.shared.layout, - &page, &(""), &content, + &page, "", &content, &cx.shared.themes); cx.shared.fs.write(&dst, v.as_bytes())?; } @@ -1921,7 +1921,7 @@ impl Context { String::new() }; let v = layout::render(&self.shared.layout, - &page, &sidebar, &all, + &page, sidebar, &all, &self.shared.themes); self.shared.fs.write(&final_file, v.as_bytes())?; @@ -1937,7 +1937,7 @@ impl Context { themes.push(PathBuf::from("settings.css")); let v = layout::render( &self.shared.layout, - &page, &sidebar, &settings, + &page, sidebar, &settings, &themes); self.shared.fs.write(&settings_file, v.as_bytes())?; @@ -1994,7 +1994,7 @@ impl Context { if !self.render_redirect_pages { layout::render(&self.shared.layout, &page, - &Sidebar{ cx: self, item: it }, + Sidebar{ cx: self, item: it }, &Item{ cx: self, item: it }, &self.shared.themes) } else { @@ -4267,7 +4267,7 @@ fn item_foreign_type(w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item) } impl Print for Sidebar<'_> { - fn print(&self, buffer: &mut Buffer) { + fn print(self, buffer: &mut Buffer) { let cx = self.cx; let it = self.item; let parentlen = cx.current.len() - if it.is_mod() {1} else {0}; -- cgit 1.4.1-3-g733a5