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
/// This macros provides the usefull reading buffer by using [io::stdin](std::io::stdin) /// /// # Examples: /// ``` /// use add_macro::input; /// /// let buf: String = input!("Type something: "); /// println!("{buf}"); /// ``` #[macro_export] macro_rules! input { () => {{ let mut buf = String::new(); if let Ok(_) = std::io::stdin().read_line(&mut buf) { buf.trim().to_owned() } else { String::new() } }}; ($($arg:tt)*) => {{ eprint!($($arg)*); input!() }}; }