I read about reading integer input in How to read an integer input from the user in Rust 1.0?, but I noticed that all the solutions first take a string as input and then convert it to integer. I wonder if there's a way to read an integer directly.
This page mentions scan!()
macro but for some reason it doesn't seem to run when I compile the following program using rustc main.rc
.
extern crate text_io;
fn main() {
let mut a: u8;
let mut b: u8;
scan!("{},{}", a, b);
print!("{} {}", a, b);
}
This produces the error:
error: macro undefined: 'scan!'
scan!("{},{}",a,b);
You have to explicitly say that you want to import macros from this crate:
This is written at the very top of the readme, you must have missed it.
To use crates from crates.io, you need to add them to your
Cargo.toml
, for example by adding the following lines to that file: