Enum IoArg

Source
pub enum IoArg {
    StdStream,
    File(PathBuf),
}
Expand description

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 clap::Parser;
use io_arg::IoArg;

#[derive(Debug, Parser)]
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§

Source§

impl IoArg

Source

pub fn is_file(&self) -> bool

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.

Source

pub fn open_as_input(self) -> Result<Input>

Either calls stdin or File::open depending on io_arg.

Source

pub fn open_as_output(self) -> Result<Output>

Either calls stdout or File::create depending on io_arg.

Trait Implementations§

Source§

impl Clone for IoArg

Source§

fn clone(&self) -> IoArg

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IoArg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for IoArg

Source§

type Err = Infallible

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for IoArg

Source§

fn eq(&self, other: &IoArg) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for IoArg

Source§

impl StructuralPartialEq for IoArg

Auto Trait Implementations§

§

impl Freeze for IoArg

§

impl RefUnwindSafe for IoArg

§

impl Send for IoArg

§

impl Sync for IoArg

§

impl Unpin for IoArg

§

impl UnwindSafe for IoArg

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.