Skip to content

Commit a2e0222

Browse files
committed
Document Error and locale APIs for docs.rs
Match crate-level rustdoc to the README pitch (native backends, not Spellbook) and document Error variants, locale(), available_locales(), and range(). Set Cargo.toml homepage for crates.io.
1 parent dfefc86 commit a2e0222

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This project follows [Semantic Versioning](https://semver.org/).
1313
- Removed the crate binary (`src/main.rs`); use `examples/`
1414

1515
### Changed
16+
- Crate-level rustdoc and docs on `Error`, `locale`, `available_locales`, and `range`
1617
- Document platform defaults for `Checker::new()`, locale failure, suggestions cap, and UTF-8 error ranges in rustdoc
1718
- README now states that macOS `Checker::new()` uses the system language
1819
- `Checker` is no longer `Send`/`Sync`

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ description = "Cross-platform native spell checking for Rust (NSSpellChecker, Wi
44
keywords = ["spellcheck", "spellchecker", "hunspell", "nsspellchecker"]
55
categories = ["os", "text-processing"]
66
documentation = "https://docs.rs/spellkit"
7+
homepage = "https://github.com/rtmongold/spellkit"
78
repository = "https://github.com/rtmongold/spellkit"
89
version = "0.3.0"
910
authors = [

src/lib.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
//! `spellkit` is a small crate that binds to the native platform's spell checking APIs and
2-
//! provides a friendlier API.
3-
//!
4-
//! This corresponds to [`ISpellChecker`] on Windows, [`NSSpellChecker`] on MacOS, and [`hunspell`]
5-
//! on other *nix platforms.
1+
//! Cross-platform native spell checking: [`NSSpellChecker`] on macOS, [`ISpellChecker`]
2+
//! on Windows, and [`hunspell`] with system dictionaries on other Unix.
63
//!
74
//! Spellkit does not bundle dictionaries or implement its own spelling algorithm.
8-
//! It wraps the platform backend and uses system / installed dictionaries.
9-
//! Behavior can differ across operating systems where the underlying APIs differ.
5+
//! Use it when you want OS dictionaries and a small API; use a crate like Spellbook
6+
//! when you want a portable engine and app-shipped word lists.
7+
//! Behavior can differ across operating systems where the backends differ.
108
//!
119
//! # Example
1210
//!
@@ -35,16 +33,28 @@ use std::marker::PhantomData;
3533
use std::ops::Range;
3634
use std::path::PathBuf;
3735

36+
/// Failure creating a [`Checker`].
37+
///
38+
/// Match on this instead of a single “unavailable” flag: Linux can report missing
39+
/// Hunspell files, while macOS and Windows report an unsupported language tag.
3840
#[derive(Clone, Debug, PartialEq, Eq)]
3941
pub enum Error {
42+
/// The locale string was empty or could not be normalized.
4043
InvalidLocale,
44+
/// The OS has no spell checker for this language (macOS / Windows).
4145
UnsupportedLocale {
4246
locale: String,
4347
},
48+
/// No Hunspell `.aff` / `.dic` pair was found (Linux / other Unix).
49+
///
50+
/// `searched` is the directory list that was walked (`DICPATH` then the
51+
/// built-in system paths).
4452
DictionaryNotFound {
4553
locale: String,
4654
searched: Vec<PathBuf>,
4755
},
56+
/// The backend started but failed (null Hunspell handle, COM factory, empty
57+
/// macOS system language).
4858
InitializationFailed {
4959
locale: Option<String>,
5060
message: String,
@@ -108,6 +118,7 @@ cfg_if! {
108118
/// Instance of the system spell checker.
109119
///
110120
/// `Checker` is not `Send` or `Sync`. Do not share it across threads.
121+
/// macOS also serializes access to the shared `NSSpellChecker`.
111122
#[derive(Debug)]
112123
pub struct Checker(imp::Checker, PhantomData<*const ()>);
113124

@@ -169,10 +180,18 @@ impl Checker {
169180
self.0.ignore(word)
170181
}
171182

183+
/// Language tag this checker is using (Hunspell `en_US` or BCP-47 `en-US`).
184+
///
185+
/// After [`Checker::new`] this is the locale that was actually selected, not
186+
/// a placeholder for “system default.”
172187
pub fn locale(&self) -> &str {
173188
self.0.locale()
174189
}
175190

191+
/// Locales the OS can check.
192+
///
193+
/// Linux: Hunspell `*.dic` stems on `DICPATH` and the system dict dirs.
194+
/// macOS: `NSSpellChecker` available languages. Windows: `SupportedLanguages`.
176195
pub fn available_locales() -> Vec<String> {
177196
imp::Checker::available_locales()
178197
}
@@ -197,6 +216,7 @@ impl SpellingError {
197216
self.0.end()
198217
}
199218

219+
/// UTF-8 byte range of the misspelling: `start()..end()`.
200220
pub fn range(&self) -> Range<usize> {
201221
self.start()..self.end()
202222
}

0 commit comments

Comments
 (0)