Expand description
A pattern that often occurs when writing command-line utilities is that one wants to open a file when a filename argument is provided or read/write from/to stdin/stdout otherwise. Unfortunatlely, this is more work in Rust than it should be.
The stdinout
crate provides a small wrapper that makes it easier
to handle this scenario.
For reading from a file or the standard input:
ⓘ
let input = Input::from(matches.free.get(0));
let reader = or_exit(input.buf_read());
for line in reader.lines() {
// Use 'line'
}
For writing to a file or the standard output:
ⓘ
let output = Output::from(args.get(1));
// Get an object that implements the Write trait.
let write = output.write().unwrap();
Structs§
Enums§
Traits§
- OrExit
- Types implementing the
OrExit
provide theor_exit
function that can be used to exit a program when a computation was not successful.