#suggestions #mean #did #distance #collection #run-time #standard

suggest

A minimal library to provide similar name suggestions like "Did you mean?"

3 unstable releases

0.5.1 Feb 14, 2024
0.5.0 Apr 26, 2023
0.4.0 May 9, 2022

#220 in Data structures

Download history 809/week @ 2024-01-30 750/week @ 2024-02-06 869/week @ 2024-02-13 981/week @ 2024-02-20 1001/week @ 2024-02-27 740/week @ 2024-03-05 714/week @ 2024-03-12 669/week @ 2024-03-19 619/week @ 2024-03-26 711/week @ 2024-04-02 778/week @ 2024-04-09 1217/week @ 2024-04-16 1285/week @ 2024-04-23 1127/week @ 2024-04-30 826/week @ 2024-05-07 755/week @ 2024-05-14

4,245 downloads per month
Used in 3 crates

MIT license

11KB
134 lines

suggest crates.io version crates.io downloads

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.

Installation

Add the following to your Cargo.toml:

[dependencies]
suggest = "0.5"

Examples

Simple case

This example can be executed by the cargo run --example simple command.

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);
    }
}
$ cargo run
No command named `instakk` found.
Did you mean `install`?

Specifying distance

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);
    }
}
$ 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

$ cargo build

Test

$ cargo build
$ cargo test

Publish

GitHub Releases

$ git tag v0.1.0
$ git push origin v0.1.0

crates.io

$ cargo publish

Dependencies

~13KB