Writing to Stdout/Stderr on Windows
⚓ Rust 📅 2025-10-06 👤 surdeus 👁️ 6I don't have a Windows machine to test on, and I'm worried that my code may cause an unexpected error when writing to StdoutLock<'_>/StderrLock<'_> on Windows. According to the docs:
When operating in a console, the Windows implementation of this stream does not support non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return an error.
Do I have to worry about the internal buffer of StdoutLock<'_> or BufWriter<StderrLock<'_>> getting flushed to the underlying stream in a way that splits a multi-byte Unicode scalar value (USV) causing an error when I only write strs? Even if I were to use LineWriter for StderrLock<'_>, the docs seem to suggest that it's possible the internal buffer is flushed before a newline seemingly opening up the possibility of splitting a USV (emphasis added):
Like
BufWriter, aLineWriter’s buffer will also be flushed when theLineWritergoes out of scope or when its internal buffer is full.
Must I use my own buffer that guarantees any flushes that occur do so on a USV boundary?
2 posts - 2 participants
🏷️ Rust_feed