Skip to main content

Module out

Module out 

Source
Expand description

Every byte proc writes to stdout or stderr goes through this module.

println! and friends panic when the write fails, and Rust ignores SIGPIPE, so a reader that stops early (proc list | head -n1) used to end proc with a panic and exit 101, even when the command had just killed something. The policy lives here, in one place:

  • A broken pipe means the reader is gone. Writing stops, quietly, on that stream, and the command goes on to the end and exits with the code its own result calls for: a kill that worked exits 0, a not-found exits 2. A broken pipe on stderr changes nothing either.
  • Any other write error (a full disk, a file size limit, an I/O error) is a failure: nothing more is written to that stream, and finish turns an exit 0 into exit 1 and says why on stderr, if stderr still works. A command that already failed keeps its own, more specific exit code.
  • Nothing here panics, and nothing writes about a broken pipe.

The commands print through out_println!, out_print!, err_println! and err_print!, or through the writers stdout and stderr. The failure is recorded on the stream when it happens, so a deep helper does not need to pass an error up through every caller; main reads it back once, in finish, and unwinds normally (destructors and terminal restore still run). clippy.toml bans the std print macros and std::io::stdout/stderr everywhere else, so a new direct print fails cargo clippy -- -D warnings.

Structs§

Out
A writer for stdout or stderr that applies the module’s policy. Cheap to make; make one wherever a Write is wanted.
Unrecorded
A writer that goes straight to the stream, whatever has failed before.

Functions§

finish
The exit code once the command is over: code, unless a write failed.
on_stderr
Run show with everything it prints to stdout going to stderr instead.
print_stderr
Write formatted text to stderr, and a newline after it when newline is set. This is what err_print! and err_println! call.
print_stdout
Write formatted text to stdout, and a newline after it when newline is set. This is what out_print! and out_println! call.
reader_gone_within
Wait for span, or until nobody reads stdout any more; true in that case.
recorded
Settle the result of a write whose failure is already recorded on its stream (see the module docs): there is nothing left to do with it here.
stderr
The writer for stderr
stderr_is_terminal
Whether stderr is a terminal
stderr_unrecorded
The writer for stderr that ignores earlier failures (see Unrecorded)
stderr_usable
Whether stderr is still good: its reader is there and no write has failed
stdout
The writer for stdout (or for stderr, while on_stderr runs)
stdout_is_terminal
Whether stdout is a terminal
stdout_unrecorded
The writer for stdout that ignores earlier failures (see Unrecorded)
stdout_usable
Whether stdout is still good: its reader is there and no write has failed
through_stdout
Run something that prints to stdout by itself (clap’s help and version, which choose their own colours) under the same policy: a failed write is recorded, and nothing is written once stdout has failed.
write_stdout
Write bytes to stdout in one go (a generated man page or completion script)