#input #cli-input #console #user-input #shell #terminal #cli

catch-input

Library implementing a macro for retrieving user input from the console

4 stable releases

1.1.2 Apr 11, 2022
1.0.1 Apr 10, 2022

#21 in #cli-input

MIT license

5KB

catch-input

Crates.io Version Crates.io License Lines of Code

Rust library implementing a macro for retrieving user input from the console.

Example

use catch_input::input;

fn main() {
    let a = input!("PromptA => ");
    let b = input!(|| { print!("PromptB => ") });
    let c = input!((String::from("PromptC => ")));

    assert!(a, String::from("Catch"));
    assert!(b, String::from("Input"));
    assert!(c, String::from("Crate"));

    println!(">> {} : {} : {}", a, b, c);
}
$ cargo run
...

PromptA => Catch
PromptB => Input
PromptC => Crate
>> Catch : Input : Crate

lib.rs:

Library giving an easy way to fetch input from the standard input through the exported input macro.

Example

use catch_input::input;

fn main() {
    let input_a = input!("What's your favorite food? ");
    let input_b = input!(|| { print!("What's your favorite drink? ") });
    
    assert!(input_a, String::from("Oatmeal"));
    assert!(input_b, String::from("Water"));
    
    // $ cargo run
    // What's your favorite food? Oatmeal
    // What's your favorite drink? Water
}

No runtime deps