[−][src]Crate rcin
Some functions for cin like input from stdin for all types that implement FromStr
Useful for quick prototyping and debugging without passing any state around.
(And for people who complain that input in rust is too verbose)
It stores a buffer of the last line and tries to consume it first. Blocks until it finds any sequence of non whitespace characters
Depends on the lazy_static crate for storing global state
Example
let x: i32 = rcin::read_next(); // reads until it finds a valid i32 print!("Enter three numbers: "); // flushes stdout by default before any input let mut max = i32::MIN; for _ in 0..3{ let t = rcin::read_safe(); // safe = unwrap_or_default max = std::cmp::max(max, t); } println!("Max: {}", max); print!("Ready to continue?"); rcin::pause(); //wait for newline
Thread safety
Rcin is thread safe, but all threads will share one buffer. (Parallel input from stdin is not a usable thing, is it?)
pause
is not a common lock for all threads
Corner case
Does not read the input char by char like cin and requires whitespaces between groups
Reading an int:
C++: 17GRABAGE => 17 //perfectly fine lol
RCin: 17GARBAGE => None
Functions
clear | Clears the internal buffer |
consume | Clears the internal buffer and returns its contents |
pause | One-liner to await a newline |
read | One-liner to read |
read_line | One-liner to read a nonempty line |
read_next | One-liner to read until a value is valid |
read_safe | One-liner to read and apply unwrap_or_default |
set_flush | !Set to |