0.3.4 |
|
---|---|
0.3.3 |
|
0.3.0 |
|
0.2.0 |
|
0.1.0 |
|
#8 in #建议
46 每月下载
用于 2 crates
15KB
184 行
suggest
一个最小的库和命令行工具,提供类似于“你是指?”的类似名称建议。此库为标准库中的所有集合类型提供建议特质。也支持 WebAssembly 包。
此库旨在在运行时从未知建议列表中建议候选人,除了在 clap
中已有的建议功能。
示例
简单情况
此示例可以通过执行 cargo run --example simple
命令来运行。
use suggestion::Suggest;
fn main() {
let input = "instakk";
let list_commands = vec!["update", "install"];
if list_commands.contains(&input) {
return;
}
if let Some(sugg) = list_commands.suggest(input) {
println!("No command named `{}` found.", input);
println!("Did you mean `{}`?", sugg);
}
}
$ cargo run
No command named `instakk` found.
Did you mean `install`?
指定距离
use suggestion::Suggest;
fn main() {
let input = "paoc";
let list_commands = vec!["poac", "poacpp"];
if list_commands.contains(&input) {
return;
}
if let Some(sugg) = list_commands.suggest_with_dist(input, Some(2)) {
println!("No command named `{}` found.", input);
println!("Did you mean `{}`?", sugg);
}
}
$ cargo run
No command named `paoc` found.
Did you mean `poac`?
支持类型
请通过问题或拉取请求告诉我是否遗漏了任何内容。
序列
LinkedList
VecDeque
Vec
映射
HashMap
BTreeMap
要建议键,请使用 suggestion::SuggestKey
特质。
集合
BTreeSet
HashSet
其他
BinaryHeap
[T; N]
: 基本数组[T]
: 切片
命令行界面
安装
cargo install suggestion
WebAssembly
此应用程序还提供了一个 wasm 包。您可以使用以下命令使用 wapm
安装它:
$ wapm install ken-matsui/suggest
用法
$ suggest --help
suggestion 0.3.1
A minimal library & CLI tool to provide similar name suggestions like "Did you mean?"
USAGE:
suggest [OPTIONS] <INPUT> [VALUES]...
ARGS:
<INPUT> Input to check if similar name exists
<VALUES>... Values of similar names
OPTIONS:
-d, --distance <DISTANCE> Levenshtein Distance
-h, --help Print help information
-q, --quiet Disable console outputs
-V, --version Print version information
WebAssembly
$ wapm run suggest --help
...
示例
$ suggest instakk update install
The `instakk` input is similar to `install`.
$ suggest hoge update install
No similar name for the `hoge` input was found.
$ suggest install update install
The same value with the `install` input exists.
$ suggest paoc poac poacpp
No similar name for the `paoc` input was found.
$ suggest paoc poac poacpp --distance 2
The `paoc` input is similar to `poac`.
WebAssembly
$ wapm run suggest instakk update install
The `instakk` input is similar to `install`.
$ wapm run suggest hoge update install
No similar name for the `hoge` input was found.
$ wapm run suggest install update install
The same value with the `install` input exists.
$ wapm run suggest paoc poac poacpp
No similar name for the `paoc` input was found.
$ wapm run suggest paoc poac poacpp --distance 2
The `paoc` input is similar to `poac`.
贡献
欢迎贡献,包括问题和拉取请求。
构建
$ cargo build
或者您可以直接执行二进制文件
$ cargo run
WebAssembly
$ rustup target add wasm32-wasi
$ cargo build --target wasm32-wasi
$ wasmer run target/wasm32-wasi/debug/suggest.wasm encode hello
测试
此命令也可以测试 C API。
$ cargo build
$ cargo test
发布
GitHub 发布
$ git tag v0.1.0
$ git push origin v0.1.0
crates.io
$ cargo publish
wapm.io
$ cargo build --release --target wasm32-wasi
$ wapm publish
依赖
~3MB
~61K SLoC