Created
March 3, 2019 04:27
-
-
Save andraantariksa/e64fe5b789288122d1159d57a15398fc to your computer and use it in GitHub Desktop.
Rust simple input macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! input_vec { | |
() => { | |
input!() | |
.split_whitespace() | |
.map(|x| x.parse().unwrap()) | |
.collect() | |
}; | |
($delimiter:expr) => { | |
input!() | |
.split($delimiter) | |
.map(|x| x.parse().unwrap()) | |
.collect() | |
}; | |
} | |
macro_rules! read_line { | |
() => {{ | |
let mut return_ = format!(""); | |
std::io::stdin().read_line(&mut return_).unwrap(); | |
return_.pop(); | |
return_ | |
}}; | |
} | |
fn main() { | |
let v: Vec<i32> = input_vec!(); | |
let input: String = input!() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment