Expand description

input-macro - No-nonsense input!(…) macro for Rust.

Example

use input_macro::{confirm, 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! 🥳");
        },
    }

    if confirm!("Do you like chocolate 🍫 (yes/no)? ") {
        println!("Yay! I like chocolate too 🙂.");
    } else {
        println!("Oh well, all the more for me 😋.");
    }
}

Macros

Displays the formatted prompt to the standard output then reads lines (CR or CRLF) from the standard input, until either a ‘yes’ or a ‘no’ answer is recorded. Returns bool.

Displays the formatted prompt to the standard output then reads the next line (CR or CRLF) from the standard input, and returns it as a String.

Attempts to display the formatted prompt to the standard output then reads lines (CR or CRLF) from the standard input, until either a ‘yes’ or a ‘no’ answer is recorded. Returns io::Result<bool> (see confirm! for more).

Attempts to display the formatted prompt to the standard output then read the next line (CR or CRLF) from the standard input. Returns io::Result<String> (see input! for more).

Functions

Return whether s is a ‘yes’, ‘no’, or ‘other’ answer.

Reads the next available line (without CR/CRLF) from the standard input.