Enum io_arg::IoArg [−][src]
pub enum IoArg { StdStream, File(PathBuf), }
Argument for CLI tools which can either take a file or STDIN/STDOUT.
Caveat: stdin is represented as “-” at the command line. Which means your tool is going to have a hard time operating on a file named “-”.
use structopt::StructOpt; use io_arg::IoArg; #[derive(Debug, StructOpt)] struct Cli { /// Path to input file. Set to "-" to use STDIN instead of a file. input: IoArg, /// Path to output file. Leave out or set to "-" to use STDOUT instead of a file. output: IoArg, }
Variants
Indicates that the IO is connected to stdin/stdout. Represented as a “-” on the command line.
File(PathBuf)
Indicates that the IO is connected to a file. Contains the file path. Just enter a path at the command line.
Implementations
impl IoArg
[src]
impl IoArg
[src]pub fn is_file(&self) -> bool
[src]
Intended for use in an if
expression or other situations there a boolean might be more
convinient than matching against variants.
Return
true
if variant is File
.
false
if variant is StdStream
.
pub fn open_as_input(self) -> Result<Input>
[src]
Either calls stdin
or File::open
depending on io_arg
.
pub fn open_as_output(self) -> Result<Output>
[src]
Either calls stdout
or File::create
depending on io_arg
.
Trait Implementations
impl StructuralEq for IoArg
[src]
impl StructuralEq for IoArg
[src]impl StructuralPartialEq for IoArg
[src]
impl StructuralPartialEq for IoArg
[src]Auto Trait Implementations
impl RefUnwindSafe for IoArg
impl RefUnwindSafe for IoArg
impl UnwindSafe for IoArg
impl UnwindSafe for IoArg