RFC 1014: stdout-existential-crisis

libs (panic | input-output)

Summary

When calling println! it currently causes a panic if stdout does not exist. Change this to ignore this specific error and simply void the output.

Motivation

On Linux stdout almost always exists, so when people write games and turn off the terminal there is still an stdout that they write to. Then when getting the code to run on Windows, when the console is disabled, suddenly stdout doesn't exist and println! panicks. This behavior difference is frustrating to developers trying to move to Windows.

There is also precedent with C and C++. On both Linux and Windows, if stdout is closed or doesn't exist, neither platform will error when attempting to print to the console.

Detailed design

When using any of the convenience macros that write to either stdout or stderr, such as println! print! panic! and assert!, change the implementation to ignore the specific error of stdout or stderr not existing. The behavior of all other errors will be unaffected. This can be implemented by redirecting stdout and stderr to std::io::sink if the original handles do not exist.

Update the methods std::io::stdin std::io::stdout and std::io::stderr as follows:

Drawbacks

Alternatives

Unresolved questions