Skip to content

Commit 25e26e5

Browse files
authored
Document Error and locale APIs for docs.rs (#19)
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 25e26e5

3 files changed

Lines changed: 30 additions & 10 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: 28 additions & 10 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,26 @@ 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,
41-
UnsupportedLocale {
42-
locale: String,
43-
},
44+
/// The OS has no spell checker for this language (macOS / Windows).
45+
UnsupportedLocale { locale: String },
46+
/// No Hunspell `.aff` / `.dic` pair was found (Linux / other Unix).
47+
///
48+
/// `searched` is the directory list that was walked (`DICPATH` then the
49+
/// built-in system paths).
4450
DictionaryNotFound {
4551
locale: String,
4652
searched: Vec<PathBuf>,
4753
},
54+
/// The backend started but failed (null Hunspell handle, COM factory, empty
55+
/// macOS system language).
4856
InitializationFailed {
4957
locale: Option<String>,
5058
message: String,
@@ -108,6 +116,7 @@ cfg_if! {
108116
/// Instance of the system spell checker.
109117
///
110118
/// `Checker` is not `Send` or `Sync`. Do not share it across threads.
119+
/// macOS also serializes access to the shared `NSSpellChecker`.
111120
#[derive(Debug)]
112121
pub struct Checker(imp::Checker, PhantomData<*const ()>);
113122

@@ -169,10 +178,18 @@ impl Checker {
169178
self.0.ignore(word)
170179
}
171180

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

189+
/// Locales the OS can check.
190+
///
191+
/// Linux: Hunspell `*.dic` stems on `DICPATH` and the system dict dirs.
192+
/// macOS: `NSSpellChecker` available languages. Windows: `SupportedLanguages`.
176193
pub fn available_locales() -> Vec<String> {
177194
imp::Checker::available_locales()
178195
}
@@ -197,6 +214,7 @@ impl SpellingError {
197214
self.0.end()
198215
}
199216

217+
/// UTF-8 byte range of the misspelling: `start()..end()`.
200218
pub fn range(&self) -> Range<usize> {
201219
self.start()..self.end()
202220
}

0 commit comments

Comments
 (0)