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

StdStream

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]

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 Debug for IoArg[src]

impl Eq for IoArg[src]

impl FromStr for IoArg[src]

type Err = Infallible

The associated error which can be returned from parsing.

impl PartialEq<IoArg> for IoArg[src]

impl StructuralEq for IoArg[src]

impl StructuralPartialEq for IoArg[src]

Auto Trait Implementations

impl RefUnwindSafe for IoArg

impl Send for IoArg

impl Sync for IoArg

impl Unpin for IoArg

impl UnwindSafe for IoArg

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.