Don't forget to add the plugin to your crate:
extern crate text_io;
You can use either the read!
macro to read a single value and return it, or
the scan!
macro to read one or more values into variables. Both macros can
also read from a file or from memory. The read!
macro can take any type that
implements Iterator<Item=u8>
as an optional third argument, and the scan!
macro's arguments can be prefixed with iter =>
where iter
implements
Iterator<Item=u8>
.
#Examples
##scan! macro
// reading from a string source
let i: i32;
scan!;
assert_eq!;
// reading multiple values from stdio
let a: i32;
let b: &mut u8 = &mut 5;
scan!;
##read! macro
// read until a whitespace and try to convert what was read into an i32
let i: i32 = read!;
// read until a whitespace (but not including it)
let word: String = read!; // same as read!("{}")
// read until a newline (but not including it)
let line: String = read!;
// expect the input "<b><i>" or panic
// read until the next "<" and return that.
// expect the input "/i></b>"
let stuff: String = read!;
// reading from files
use Read;
let mut file = open.unwrap.bytes.map;
let val: i32 = read!;
// reading from strings
let val: i32 = read!;