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