Skip to content

Instantly share code, notes, and snippets.

@xkr47
Last active December 14, 2022 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xkr47/191bead8f0ccc5954744e297cbf8942c to your computer and use it in GitHub Desktop.
Save xkr47/191bead8f0ccc5954744e297cbf8942c to your computer and use it in GitHub Desktop.
UTF-8 -emitting fmt::Write wrapper for io::Write
struct FmtWriter<W: std::io::Write>(W);
impl <W: std::io::Write> std::fmt::Write for FmtWriter<W> {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.0.write_all(s.as_bytes()).map_err(|_| fmt::Error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment