[][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.


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

input-stream = "0.3.0"

and this in your crate root:

extern crate input_stream;


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);



A wrapper for std::io::BufRead.



The type of errors this library can return.

Type Definitions


A specialized Result for this library's errors.