From 5ebcb4c3bfe2f424734bd1b39a0e80ed82a88aaf Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Mar 2023 13:37:40 -0500 Subject: [PATCH] feat(builder): Allow `write!` on StyledStr --- clap_builder/src/builder/styled_str.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clap_builder/src/builder/styled_str.rs b/clap_builder/src/builder/styled_str.rs index 9130ac44d9a..cf52ab589f0 100644 --- a/clap_builder/src/builder/styled_str.rs +++ b/clap_builder/src/builder/styled_str.rs @@ -197,6 +197,20 @@ impl From<&'_ &'static str> for StyledStr { } } +impl std::fmt::Write for StyledStr { + #[inline] + fn write_str(&mut self, s: &str) -> Result<(), std::fmt::Error> { + self.0.push_str(s); + Ok(()) + } + + #[inline] + fn write_char(&mut self, c: char) -> Result<(), std::fmt::Error> { + self.0.push(c); + Ok(()) + } +} + /// Color-unaware printing. Never uses coloring. impl std::fmt::Display for StyledStr { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {