4 个稳定版本
1.1.2 | 2022年4月11日 |
---|---|
1.0.1 | 2022年4月10日 |
#995 在 命令行界面
5KB
catch-input
一个 Rust 库,实现了从控制台获取用户输入的宏。
示例
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
:
通过导出的 input
宏,提供一种方便获取标准输入的方法。
示例
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
}