From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/tabled/src/tables/util/mod.rs | 2 ++ vendor/tabled/src/tables/util/utf8_writer.rs | 29 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 vendor/tabled/src/tables/util/mod.rs create mode 100644 vendor/tabled/src/tables/util/utf8_writer.rs (limited to 'vendor/tabled/src/tables/util') diff --git a/vendor/tabled/src/tables/util/mod.rs b/vendor/tabled/src/tables/util/mod.rs new file mode 100644 index 000000000..ea5453b8f --- /dev/null +++ b/vendor/tabled/src/tables/util/mod.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "std")] +pub(crate) mod utf8_writer; diff --git a/vendor/tabled/src/tables/util/utf8_writer.rs b/vendor/tabled/src/tables/util/utf8_writer.rs new file mode 100644 index 000000000..d4fc515df --- /dev/null +++ b/vendor/tabled/src/tables/util/utf8_writer.rs @@ -0,0 +1,29 @@ +use std::fmt; +use std::io; + +pub(crate) struct UTF8Writer(W); + +impl UTF8Writer { + pub(crate) fn new(writer: W) -> Self { + Self(writer) + } +} + +impl fmt::Write for UTF8Writer +where + W: io::Write, +{ + fn write_str(&mut self, s: &str) -> fmt::Result { + let mut buf = s.as_bytes(); + loop { + let n = self.0.write(buf).map_err(|_| fmt::Error)?; + if n == buf.len() { + break; + } + + buf = &buf[n..]; + } + + Ok(()) + } +} -- cgit v1.2.3