pub struct Console<O: Write + Send, E: Write + Send> { /* private fields */ }Expand description
console: line-oriented output on two streams.
The two writers are the whole of the difference between the streams. What
a program produces goes to out through println and print; what it
says about what it produces goes to err through eprintln and eprint,
and a host that wants the two apart is a host that hands over two
different writers. cove run gives the process’s stdout and stderr, which
is why a program’s records can now be piped somewhere while its complaints
stay on the terminal.
The two streams are one capability. All four operations require
console, so a run that may print may complain, and this type is where
the difference between the streams is: an embedding that wants a program’s
output captured while its complaints reach the terminal hands over a
buffer and std::io::stderr(), which is a wiring choice rather than an
authority one. Nothing here consults the grants at all — the boundary has
already decided by the time an operation arrives.
§Migrating from the one-writer form
Console::new took one writer and now takes two. The second is where
diagnostics go, and there is deliberately no default: a host that captured
a program’s output before this existed would silently start capturing its
diagnostics too, which is exactly the mixing the second stream is for
undoing. Console::new(w) therefore fails to compile rather than changing
meaning. An embedding that genuinely wants one stream says so —
Console::new(w.clone(), w) for a shared writer, Console::new(w, std::io::sink()) to drop diagnostics — and one that wants the process’s
streams writes Console::new(std::io::stdout(), std::io::stderr()).