Skip to content

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

License

Notifications You must be signed in to change notification settings

sunsetkookaburra/input-macro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

input-macro

Repository Crate Page Documentation License

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 😋.");
        },
    }
}

License

MPL v2.0, see LICENSE