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

Displays formatted prompt text to the standard output and then reads the next line from the standard input, returning it as a String.

Functions

Writes and flushes a formatted string as prompt text to the dst (Write) then reads the next line from the src (io::BufRead), returning it as a io::Result<String>.

Reads the next line from src (io::BufRead), mapping EOF to io::ErrorKind::UnexpectedEof and returning a io::Result<String>.