Coder Social home page Coder Social logo

suggest's Introduction

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

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

suggest's People

Contributors

ken-matsui avatar dependabot[bot] avatar

Stargazers

Yasuharu Sawada avatar Fredrick Makoffu Mbugua avatar Ben Bachem avatar Jordan Mackie avatar Tatsuya Kawano avatar Kodai Kabasawa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.