pub enum Input {
    Stdin(Stdin),
    Pipe(OsStringFile),
    File(OsStringFile),
}
Expand description

An enum that represents a command line input stream, either std in or a file

It is designed to be used with the clap crate when taking a file name as an argument to CLI app

use clap::Parser;
use clio::Input;

#[derive(Parser)]
struct Opt {
    /// path to file, use '-' for stdin
    #[clap(parse(try_from_os_str = TryFrom::try_from))]
    input_file: Input,
}

Variants

Stdin(Stdin)

Pipe(OsStringFile)

File(OsStringFile)

Implementations

Contructs a new input either by opening the file or for ‘-’ returning stdin

Contructs a new input either by opening the file or for ‘-’ returning stdin

The error is converted to a OsString so that stuctopt can show it to the user.

It is recomended that you use TryFrom::try_from and clap 3.0 instead.

If input is a file, returns the size of the file, in bytes otherwise if input is stdin returns none.

Examples
let file = clio::Input::new("foo.txt").unwrap();

assert_eq!(Some(3), file.len());

Returns a boolean saying if the file is empty, if using stdin returns None

Examples
let file = clio::Input::new("foo.txt").unwrap();

assert_eq!(Some(true), file.is_empty());

If the input is std in locks it, otherwise wraps the file in a buffered reader. This is useful to get the line iterator of the BufRead.

Examples
use std::io::BufRead;
let mut file = clio::Input::new("-")?;

for line in file.lock().lines() {
  println!("line is: {}", line?);
}

Returns the path/url used to create the input

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

Like read, except that it reads into a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

Read all bytes until EOF in this source, placing them into buf. Read more

Read all bytes until EOF in this source, appending them to buf. Read more

Read the exact number of bytes required to fill buf. Read more

🔬 This is a nightly-only experimental API. (read_buf)

Pull some bytes from this source into the specified buffer. Read more

🔬 This is a nightly-only experimental API. (read_buf)

Read the exact number of bytes required to fill buf. Read more

Creates a “by reference” adaptor for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

🔬 This is a nightly-only experimental API. (seek_stream_len)

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.