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
killthat 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
finishturns 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
Writeis 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
showwith everything it prints to stdout going to stderr instead. - print_
stderr - Write formatted text to stderr, and a newline after it when
newlineis set. This is whaterr_print!anderr_println!call. - print_
stdout - Write formatted text to stdout, and a newline after it when
newlineis set. This is whatout_print!andout_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_stderrruns) - 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)