1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
//! This is my first crate. Its task is to facilitate the programmer's work by allowing the use of the well-known function "input()".
//!
//! This works the same way as in python, only you need to write '!', since this is a macro: "input!()" or "input!("Enter your name: ")".
/// Outputs (or not) text and awaiting input.
//use std::io::{stdin, self, Write};
/// Outputs (or not) text and awaiting input.
#[macro_export]
macro_rules! input {
() => {{
use std::io::{stdin, self, Write};
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
buf
}};
($arg:tt) => {{
use std::io::{stdin, self, Write};
let text: &str = $arg;
print!("{}", text);
io::stdout().flush().expect("flush error");
let mut buf = String::new();
stdin().read_line(&mut buf).expect("read line error");
buf
}};
}