keyhammer/lib.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (C) 2026 Robson Trasel
3
4//! # keyhammer
5//!
6//! Typo-tolerant top-k search over a compact trie, with keyboard-aware edit
7//! costs. This crate is `no_std` (it needs `alloc`), forbids `unsafe` and has
8//! no runtime dependencies.
9//!
10//! Status: M0 prototype. Queries and terms are compared per Unicode code
11//! point, as given; the [`text`] module folds case and diacritics when asked
12//! to.
13//!
14//! # Example
15//!
16//! ```
17//! use keyhammer::cost::CostModel;
18//! use keyhammer::search::{SearchConfig, Searcher};
19//! use keyhammer::trie::Trie;
20//!
21//! let trie = Trie::build(&[
22//! ("javascript", 10),
23//! ("typescript", 10),
24//! ("python", 10),
25//! ("rust", 10),
26//! ("java", 10),
27//! ])
28//! .unwrap();
29//! let costs = CostModel::qwerty();
30//! let mut searcher = Searcher::new();
31//!
32//! // "javasript" skips the 'c' of "javascript".
33//! let out = searcher
34//! .search(&trie, &costs, b"javasript", &SearchConfig::default())
35//! .unwrap();
36//! let best = &out.hits[0];
37//! assert_eq!(trie.term(best.id), "javascript");
38//! assert_eq!(best.cost, 16);
39//! ```
40
41#![no_std]
42
43extern crate alloc;
44#[cfg(test)]
45extern crate std;
46
47pub mod cost;
48pub mod highlight;
49pub mod search;
50pub mod text;
51pub mod trie;