Crate whiteread [] [src]

Crate for reading whitespace-separated values.

The crate defines a trait White, which describes types that can be parsed from whitespace-separated words, which includes eg. integers, tuples and vectors.

The definition of whitespace used in this crate is described in SplitAsciiWhitespace.

Examples

Basics

let (s, i): (String, i32) = parse_string("  answer  42 ").unwrap();

Easy reading from stdin.

let x: i32 = parse_line().unwrap();

Efficient reading from stdin (newline-agnostic) with Reader. Stops on error.

let i = std::io::stdin();
let mut i = Reader::new(i.lock());
while let Ok(f) = i.parse::<f64>() {
    println!("{}", f);
}

If you want better error handling in while-let loops (stop on end of input, but propagate all the other errors), use none_on_too_short

Reexports

pub use self::white::White;
pub use self::white::Skip;
pub use self::white::SkipAll;
pub use self::white::Lengthed;
pub use self::white::Zeroed;
pub use self::white::TooShort;
pub use self::white::ParseError;
pub use self::white::Leftovers;
pub use self::reader::Reader;
pub use self::reader::OwnedError as ReaderError;
pub use self::reader::OwnedResult as ReaderResult;

Modules

prelude

Reexports of traits containing the extension methods.

reader

This module defines the Reader struct.

stream

This module defines the StrStream trait.

white

This module defines the White trait and some helpful structs.

Functions

parse_file

Parses a whole file as a White value

parse_line

Helper function for parsing White value from one line of stdin.

parse_string

Helper function for parsing White value from string. Leftovers are considered an error.