Crate stdinout [] [src]

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 = or_stdin(args.get(0));
for line in input.unwrap().buf_read().lines() {
    // ...
}

For writing to a file or the standard output:

let output = or_stdout(args.get(1));

// Get an object that implements the Write trait.
let write = output.write();

Enums

Input
Output