Expand description
This is a simple crate that allows for easy parsing of whitespace delimited files.
It is primarily intended for competitive programming, where such files are commonly used as inputs due to being easy to parse in C and C++. This crate aims to bring this ease to Rust.
§Sample usage
§Input
42
Benjamin 2536000
0 1 1 2 3 5 8 13 21 34
§Code
use std::io::stdin;
use anyhow::Result;
use token_read::TokenReader;
fn main() -> Result<()> {
let mut input = TokenReader::new(stdin().lock());
let (n,): (usize,) = input.line()?; // Read a single value
let (name, points): (String, u64) = input.line()?; // Read several values
let values: Vec<u64> = input.line()?; // Read an array of values
let tuples: Vec<(u32, f64)> = input.take(3).collect::<Result<_, _>>()?; // Read several lines of values
// Do some processing
Ok(())
}
Modules§
- impls
- Types (currently errors) related to specific implementations of
FromTokens
Structs§
- Take
- An iterator returned from
TokenReader::take
. - Token
Reader - This struct wraps a
BufReader
to allow easy parsing of whitespace delimited files.
Enums§
- Parse
Token Pattern Error - An error returned when parsing a constant amount of tokens.
- Read
Line Error - An error returned from
TokenReader::line_raw
. - Read
Tokens Error - An error returned from
TokenReader::line
.
Traits§
- From
Tokens - A trait for types parsable from an iterator of whitespace delimited tokens.
- Line
Count - A trait for various types than can represent a number of lines.
- ToTokens
- A trait for types that can be used to create an iterator of tokens.