Expand description
§input-macro - No-nonsense input!(…) macro for Rust.
§Example
use input_macro::input;
fn main() {
let name = input!("What's your name? ");
println!("Hello, {name}!");
let age: i64 = input!("How old are you today, {name}? ").parse().unwrap();
match age {
i if i < 0 => {
println!("Whoah, negative age! Impressive! 🌌");
},
_ => {
println!("Happy Birthday! Congratulations! 🥳");
},
}
match input!("Do you like chocolate 🍫 (y/N)? ").as_str() {
"y" | "Y" => {
println!("Yay! I like chocolate too 🙂.");
},
_ => {
println!("Oh well, all the more for me 😋.");
},
}
}Macros§
- input
- Displays formatted prompt text to the standard output and
then reads the next line from the standard input,
returning it as a
String.
Functions§
- input_
fmt - Writes and flushes a formatted string as prompt text to the
dst(Write) then reads the next line from thesrc(io::BufRead), returning it as aio::Result<String>. - read_
line_ expect - Reads the next line from
src(io::BufRead), mapping EOF toio::ErrorKind::UnexpectedEofand returning aio::Result<String>.