1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! The sole owner of standard output for line-by-line rendering.
//!
//! `println!` writes through `Stdout`'s `LineWriter`, which flushes -- one
//! syscall -- on every newline. `tree` at 10 000 nodes composes 6845 lines in
//! under 12 ms and then spent roughly twice that just handing them to the
//! terminal one at a time, which is most of why it broke its own 50 ms
//! budget.
//!
//! `outln!` is the replacement. Every line goes into a `BufWriter` around the
//! stream instead of straight to the OS, and nothing reaches the terminal
//! until [`flush`] runs. `main` calls it on every path out -- success or
//! failure -- because `std::process::exit` skips `Drop`, and an unflushed
//! buffer would vanish with it rather than reach the reader.
//!
//! The buffer wraps `Stdout`, not a `StdoutLock`: a lock cannot live in a
//! `static` -- it is neither `Send` nor `Sync`, tied to the thread that took
//! it -- and holding one for the run's whole length would leave nothing free
//! to lock for the one-shot writes below the moment this buffer's first line
//! landed. `Stdout` itself locks internally, once per flush rather than once
//! per line, which is the same saving without that risk.
//!
//! A small number of one-shot writes (`USAGE`, an `Outcome`, the brief) stay
//! on plain `print!`: they hand the whole text over in a single call already,
//! so `LineWriter` never flushes mid-render for them, and they are gone
//! before this module's buffer is ever touched in the same run.
use ;
use ;
/// Writes one line into the buffer. Nothing reaches the terminal until
/// [`flush`] runs.
///
/// A broken pipe (`vivac tree | head`) is swallowed here rather than left to
/// panic the way `println!` does: the read end is gone, there is nobody left
/// to tell, and the right thing is to finish quietly instead of tearing down
/// with a panic message on a pipe that already closed.
/// Empties the buffer onto the real stream.
///
/// Called once by `main` on every path out, success or failure, and once
/// more before a failure writes to stderr, so a refusal never overtakes the
/// output that came before it.
/// Writes one line through the sole owner of standard output, in place of
/// `println!` -- see the module doc for why.
pub use outln;