symspellrs

Crates.iosymspellrs
lib.rssymspellrs
version0.1.4
created_at2025-10-26 10:18:11.134892+00
updated_at2025-10-26 10:24:46.065272+00
descriptionRust compile time library for symspell
homepage
repositoryhttps://github.com/Saphereye/symspellrs
max_upload_size
id1901176
size55,681
Adarsh Das (Saphereye)

documentation

README

symspellrs

Crates.io Docs.rs

A compact Rust library implementing a SymSpell-style fuzzy-word suggestion algorithm. It supports two primary modes:

  • Compile-time embedding — use the include_dictionary! proc-macro to embed a dictionary (and optionally a precomputed deletion index) into the binary.
  • Runtime construction — build a SymSpell instance at runtime from an iterator of (String, usize) pairs (word, frequency).

This README contains quick usage commands, example snippets and developer commands.

Quick commands

  • Run the included example (demonstrates compile-time and runtime usage):

    cargo run --example simple_usage
    
  • Run the test suite:

    cargo test --workspace
    
  • Format and lint:

    cargo fmt --all
    cargo clippy --all-targets --all-features -- -D warnings
    
  • Build release artifacts:

    cargo build --workspace --release
    

Simple usage examples

These small snippets show the most common usage patterns. See examples/simple_usage.rs for a complete runnable example.

  1. Compile-time embedding (recommended when your dictionary is static)

The include_dictionary! proc-macro reads a dictionary file at compile time (path is evaluated relative to the crate root) and returns a ready-to-use value (when precompute = true you get an EmbeddedSymSpell-like value backed by phf statics; otherwise the macro constructs a runtime SymSpell).

use symspellrs::include_dictionary;
use symspellrs::Verbosity;

// Read tests/data/words.txt at compile time and build a ready value.
let sym = include_dictionary!("tests/data/words.txt", max_distance = 2, lowercase = true);

// Query the embedded instance:
let maybe_best = sym.find_top("helo");             // Option<Suggestion>
let closest = sym.lookup("helo", 2, Verbosity::Closest);
  1. Runtime construction (dynamic dictionaries)

If you load dictionaries from the network, a database, or need to modify them at runtime, use SymSpell::from_iter or SymSpell::load_iter:

use symspellrs::{SymSpell, Verbosity};

let entries = vec![
    ("hello".to_string(), 3usize),
    ("world".to_string(), 5usize),
];

let sym = SymSpell::from_iter(2, entries);
let results = sym.lookup("helo", 2, Verbosity::Top);

Where to look

  • Example: examples/simple_usage.rs — shows both compile-time embedding and runtime builder.
  • Tests: tests/ — includes tests that exercise the compile-time macro and runtime lookup.
Commit count: 0

cargo fmt