pub trait Output {
// Required methods
fn writeln(&mut self, line: &str);
fn write(&mut self, text: &str);
fn verbose(&mut self, f: Box<dyn FnOnce() -> String>);
fn shell_command(&mut self, cmd: &str);
fn shell_line(&mut self, line: &str);
fn step_result(
&mut self,
label: &str,
success: bool,
elapsed_ms: u128,
viewport: &[String],
);
// Provided methods
fn dry_run_shell(&mut self, _cmd: &str) { ... }
fn dry_run_write(&mut self, _path: &str) { ... }
fn dry_run_delete(&mut self, _path: &str) { ... }
fn log(&mut self, mode: OutputMode, msg: &str) { ... }
fn log_exec(&mut self, mode: OutputMode, cmd: &Command) { ... }
}Expand description
Abstraction over console output, enabling tests to capture output in memory.
The three standard implementations are:
ConsoleOutput— writes to stdout, respectingquiet/verbose.StringOutput— captures everything in aStringfor assertions.MockShell’s internal output — not part of this trait, but follows the same pattern.
Implement this trait to redirect output to a logger, a file, or anywhere else.
Required Methods§
Sourcefn write(&mut self, text: &str)
fn write(&mut self, text: &str)
Write text without a trailing newline. Suppressed in quiet mode.
Sourcefn verbose(&mut self, f: Box<dyn FnOnce() -> String>)
fn verbose(&mut self, f: Box<dyn FnOnce() -> String>)
Emit a lazily-evaluated message, only in verbose mode.
The closure is only called when the implementation decides to display it, avoiding string allocation cost in non-verbose builds.
Sourcefn shell_command(&mut self, cmd: &str)
fn shell_command(&mut self, cmd: &str)
Echo a shell command about to be run (verbose mode only).
Sourcefn shell_line(&mut self, line: &str)
fn shell_line(&mut self, line: &str)
Echo a single line of output from a running shell command.
Provided Methods§
Sourcefn dry_run_shell(&mut self, _cmd: &str)
fn dry_run_shell(&mut self, _cmd: &str)
Dry-run: announce a shell command that would be executed.
Sourcefn dry_run_write(&mut self, _path: &str)
fn dry_run_write(&mut self, _path: &str)
Dry-run: announce a file that would be written.
Sourcefn dry_run_delete(&mut self, _path: &str)
fn dry_run_delete(&mut self, _path: &str)
Dry-run: announce a file or directory that would be deleted.
Sourcefn log(&mut self, mode: OutputMode, msg: &str)
fn log(&mut self, mode: OutputMode, msg: &str)
Log a message in verbose mode without any extra ceremony.
Sourcefn log_exec(&mut self, mode: OutputMode, cmd: &Command)
fn log_exec(&mut self, mode: OutputMode, cmd: &Command)
Log a command about to be executed (verbose mode).