diff options
Diffstat (limited to 'vendor/tabled/src/tables/util')
-rw-r--r-- | vendor/tabled/src/tables/util/mod.rs | 2 | ||||
-rw-r--r-- | vendor/tabled/src/tables/util/utf8_writer.rs | 29 |
2 files changed, 31 insertions, 0 deletions
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>(W); + +impl<W> UTF8Writer<W> { + pub(crate) fn new(writer: W) -> Self { + Self(writer) + } +} + +impl<W> fmt::Write for UTF8Writer<W> +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(()) + } +} |