Struct clio::CachedInput[][src]

pub struct CachedInput { /* fields omitted */ }
Expand description

A struct that contains all the connents of a command line input stream, either std in or a file

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

use structopt::StructOpt;
use clio::CachedInput;

#[derive(StructOpt)]
struct Opt {
    /// path to file, use '-' for stdin
    #[structopt(parse(try_from_os_str = CachedInput::try_from_os_str))]
    input_file: CachedInput,
}

Implementations

Reads all the data from an input into memmory and stores it in a new CachedInput.

Useful if you want to use the input twice (see reset), or need to know the size.

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.

Returns the size of the file in bytes.

Examples
let file = clio::CachedInput::try_from_os_str("foo.txt".as_ref()).unwrap();

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

Returns a boolean saying if the file is empty

Examples
let file = clio::CachedInput::try_from_os_str("foo.txt".as_ref()).unwrap();

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

Returns the path/url used to create the input

Resets the reader back to the start of the file

Returns data from the input as a Vec

Returns reference to the data from the input as a slice

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

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

Determines if this Reader can work with buffers of uninitialized memory. 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

Creates a “by reference” adapter 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

Performs the conversion.

Performs the conversion.

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.