Crate token_read

source ·
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

  • Types (currently errors) related to specific implementations of FromTokens

Structs

Enums

Traits

  • A trait for types parsable from an iterator of whitespace delimited tokens.
  • A trait for various types than can represent a number of lines.
  • A trait for types that can be used to create an iterator of tokens.