1 unstable release

Uses old Rust 2015

0.1.0 Aug 5, 2015

#22 in #input-stream

MIT license

11KB
126 lines

scan

A tokenizing/parsing utility for Rust

Allows for whitespace-delimited tokens in an input stream to be parsed as any type implementing FromStr.

Examples

extern crate scan;
use scan::Scan;

fn main() {
  let mut scanner = scan::from_stdin();
  let int = scanner.next::<i32>().unwrap();
  let int2: i32 = scanner.next().unwrap();
  println!("Integer: {}", int);
  println!("Integer 2: {}" int2);
}

Acquire

This crate can be acquired through crates.io. One thing of note is that this crate requires nightly rust, due to instability in the io module.

Documentation

Documentation is hosted here.


lib.rs:

This crate is designed to assist in parsing values out of input streams (or any other constructs which implement Read). It does so by providing a trait, Scan which can be used to tokenize and parse input.

This crate also provides an implementation of Scan, Scanner (struct.Scanner.html).

Quick Start

Simply include extern crate scan at the top of your project, add scan = "0.1.0" to your project's dependencies, and you are ready to roll!

use scan::Scan;
let mut scanner = scan::from_stdin();
let my_int = scanner.next::<i32>();
match my_int {
    Ok(int) => println!("Integer: {}", int),
    Err(e) => println!("Error: {}", e),
}

Features

This crate provides a built-in implementation of Scan: Scanner. A scanner can be constructed from any implementation of read, and helper functions are provided for concisely creating a scanner of a file or of standard input.

By default a Scanner treats whitespace (space, tab, line feed, and carriage return) as the delimiter for what to parse; however, you can also provide a different set of delimiters.

Scan allows for any structure implementing std::str::FromStr to be parsed. This includes most types built-in to the Rust language, but you may also implement FromStr for any type you define.

No runtime deps