#stream #parsing #io

input-stream

IO streams similar to C++’s streams

5 releases (3 breaking)

0.4.0 Jun 1, 2019
0.3.0 Apr 6, 2018
0.2.0 Feb 4, 2017
0.1.1 Dec 25, 2016
0.1.0 Dec 21, 2016

#867 in Rust patterns

Download history 45/week @ 2021-07-06 7/week @ 2021-07-13 9/week @ 2021-07-20 15/week @ 2021-07-27 12/week @ 2021-08-03 11/week @ 2021-08-10 3/week @ 2021-08-17 4/week @ 2021-08-24 16/week @ 2021-09-07 5/week @ 2021-09-14 3/week @ 2021-09-21 5/week @ 2021-09-28 2/week @ 2021-10-05 10/week @ 2021-10-12 3/week @ 2021-10-19

370 downloads per month

MIT license

12KB
199 lines

input-stream

A rust library oferring input streams similar to C++'s *fstreams.

Pipelines Crates.io Docs License: MIT

Usage

Module documentation with example.

License

input-stream is distributed under the MIT license.

See LICENSE.txt for details


lib.rs:

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 buf_reader = "test".as_bytes();
# use std::io::BufRead;
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);

No runtime deps