From 814f4f6f526b302bda9a464130b97502e39cc490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Tue, 16 May 2023 17:10:25 +0200 Subject: [PATCH] Improve `PadAdapter::write_char` --- library/core/src/fmt/builders.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index d2c9f980042..9227248041e 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -40,6 +40,14 @@ impl fmt::Write for PadAdapter<'_, '_> { Ok(()) } + + fn write_char(&mut self, c: char) -> fmt::Result { + if self.state.on_newline { + self.buf.write_str(" ")?; + } + self.state.on_newline = c == '\n'; + self.buf.write_char(c) + } } /// A struct to help with [`fmt::Debug`](Debug) implementations.