[][src]Crate input_stream

A small utility library for input parsing in a manner akin to C++'s istream.

It exposes a single struct InputStream which is wrapped around any object that implements std::io::BufRead.

It can parse any type which implements std::str::FromStr.

Usage

This crate is on crates.io and can be used by adding input-stream to the dependencies in your project's Cargo.toml:

[dependencies]
input-stream = "0.3.0"

and this in your crate root:

extern crate input_stream;

Examples:

use std::io;
use input_stream::InputStream;

let mut input = InputStream::new(buf_reader);
let value = input.scan::<bool>();
match value {
    Ok(value) => println!("Successfully read boolean: {}", value),
    Err(err) => println!("Error reading value: {:?}", err)
}

Reading from standard input:

use std::io;
use input_stream::InputStream;

let stdin = io::stdin();
let mut input = InputStream::new(stdin.lock());

let integer: i32 = input.scan().expect("An integer");
let string: String = input.scan().expect("A string");

println!("Read the number: {} and the string {}", integer, string);

or from a file

use std::io::{self, BufReader};
use std::fs::File;
use input_stream::InputStream;

let mut input = InputStream::new(
    BufReader::new(File::open("name_of_file.txt").expect("a file named name_of_file.txt")));

let value: f32 = input.scan().expect("A floating point number");

println!("Read a float: {}", value);

Structs

InputStream

A wrapper for std::io::BufRead.

Enums

Error

The type of errors this library can return.

Type Definitions

Result

A specialized Result for this library's errors.