[−][src]Crate stdinout
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:
ⓘThis example is not tested
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:
ⓘThis example is not tested
let output = Output::from(args.get(1)); // Get an object that implements the Write trait. let write = output.write().unwrap();
Structs
InputReader |
Enums
Input | |
Output |
Traits
OrExit | Types implementing the |