about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-02 07:11:04 +0100
committerGitHub <noreply@github.com>2022-02-02 07:11:04 +0100
commit7117b457deb03de3d28ffa68fe9d457fef0c5c5d (patch)
treecbaf6e3a20a432f3966c6eafdaf7f89a9b88eb23
parentd5f9c40e6a9ecc62432e71e886cef83a4c2c9b98 (diff)
parent62bea63888a7f1753c019852258d20788a544dfb (diff)
downloadrust-7117b457deb03de3d28ffa68fe9d457fef0c5c5d.tar.gz
rust-7117b457deb03de3d28ffa68fe9d457fef0c5c5d.zip
Rollup merge of #92758 - mfrw:mfrw/rustdoc-impl-write, r=GuillaumeGomez
librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>

Fixes: #92563
-rw-r--r--src/librustdoc/html/format.rs17
-rw-r--r--src/librustdoc/html/render/print_item.rs3
2 files changed, 18 insertions, 2 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 08840626259..f4df9ef4a8c 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -64,6 +64,23 @@ crate struct Buffer {
     buffer: String,
 }
 
+impl core::fmt::Write for Buffer {
+    #[inline]
+    fn write_str(&mut self, s: &str) -> fmt::Result {
+        self.buffer.write_str(s)
+    }
+
+    #[inline]
+    fn write_char(&mut self, c: char) -> fmt::Result {
+        self.buffer.write_char(c)
+    }
+
+    #[inline]
+    fn write_fmt(self: &mut Self, args: fmt::Arguments<'_>) -> fmt::Result {
+        self.buffer.write_fmt(args)
+    }
+}
+
 impl Buffer {
     crate fn empty_from(v: &Buffer) -> Buffer {
         Buffer { for_html: v.for_html, buffer: String::new() }
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs
index f2c111495ed..6592a56ba46 100644
--- a/src/librustdoc/html/render/print_item.rs
+++ b/src/librustdoc/html/render/print_item.rs
@@ -139,8 +139,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
         src_href: src_href.as_deref(),
     };
 
-    let heading = item_vars.render().unwrap();
-    buf.write_str(&heading);
+    item_vars.render_into(buf).unwrap();
 
     match *item.kind {
         clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items),