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;
3533use std:: ops:: Range ;
3634use 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 ) ]
3941pub 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 ) ]
112123pub 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