Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ken-matsui/suggest
A minimal library to provide similar name suggestions, "Did you mean?"
https://github.com/ken-matsui/suggest
Last synced: 2 months ago
JSON representation
A minimal library to provide similar name suggestions, "Did you mean?"
- Host: GitHub
- URL: https://github.com/ken-matsui/suggest
- Owner: ken-matsui
- License: mit
- Created: 2021-11-11T01:37:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-02T01:25:46.000Z (3 months ago)
- Last Synced: 2024-11-01T04:51:44.323Z (2 months ago)
- Language: Rust
- Homepage: https://crates.io/crates/suggest
- Size: 103 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# suggest [![crates.io version](https://img.shields.io/crates/v/suggest.svg)](https://crates.io/crates/suggest) [![crates.io downloads](https://img.shields.io/crates/d/suggest.svg)](https://crates.io/crates/suggest)
A minimal library to provide similar name suggestions like "Did you mean?"
This library provides suggestion traits for all collection types in the standard library.This library is intended to suggest a candidate from a list of unknown suggestions until runtime, in addition to the suggestion feature already available in [`clap`](https://github.com/clap-rs/clap#default-features).
## Installation
Add the following to your `Cargo.toml`:
```toml
[dependencies]
suggest = "0.5"
```## Examples
### Simple case
This example can be executed by the `cargo run --example simple` command.
```rust
use suggest::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);
}
}
``````shell
$ cargo run
No command named `instakk` found.
Did you mean `install`?
```### Specifying distance
```rust
use suggest::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_by(input, 2) {
println!("No command named `{}` found.", input);
println!("Did you mean `{}`?", sugg);
}
}
``````shell
$ cargo run
No command named `paoc` found.
Did you mean `poac`?
```## Supported types
Please let me know if anything is left out through issues or pull requests.
### Sequences
* `LinkedList`
* `VecDeque`
* `Vec`### Maps
* `HashMap`
* `BTreeMap`To suggest keys, use `suggest::SuggestKey` trait.
### Sets
* `BTreeSet`
* `HashSet`### Misc
* `BinaryHeap`
* `[T; N]`: primitive array
* `[T]`: slices## Contribution
Contributions, including issues and pull requests, are very welcome.
### Build
```bash
$ cargo build
```### Test
```bash
$ cargo build
$ cargo test
```### Publish
#### [GitHub Releases](https://github.com/ken-matsui/suggest/tags)
```bash
$ git tag v0.1.0
$ git push origin v0.1.0
```#### [crates.io](https://crates.io/)
```bash
$ cargo publish
```