#用户输入 #自动补全 #可选 #接受 #自动 #完成 #字符串

user_input_with_autocomplete

此 crate 的唯一目的是提供简单易用的功能,以接受用户输入,并提供可选的自动补全功能

2 个版本

0.1.2 2021 年 12 月 17 日
0.1.1 2021 年 12 月 16 日

#9 in #接受

MIT 许可证

11KB
122

用户输入与自动补全

此 crate 提供了一种获取用户输入的方式,具有可选的自动补全功能。非常简单易用,输入解析也是以非常简单的方式进行。

用法

要使用此 crate,您需要将以下内容添加到您的 Cargo.toml

[dependencies]
user_input_with_autocomplete = "*" # or just copy the current crate version number istead of *

要在代码中使用它,您需要导入 user_input_with_autocomplete crate

use user_input_with_autocomplete::input::UserInput;

然后您可以使用 UserInput 结构体来获取用户输入

// Example
fn main() {
    let a = UserInput::new("Enter a number: ", None); // Here the first argument to the constructor of the struct is the prompt, and the second argument is to use auto-complete or not.
    // To use the auto-complete feature instead of None, you need to provide a function of the following type
    // ```Some(fn(String) -> String)```
    let b = a.to_string();
    let c: i32 = a.parse().unwrap(); // It's simple to parse the input and you can even parse it as a vector of strings or specified type, seperated by spaces.

}

功能

  • autocomplete - 此功能启用自动补全功能。

许可证

MIT

贡献

请随意提交问题、提交拉取请求或提出建议。

依赖关系

~4–15MB
~168K SLoC