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;
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 ,
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 ) ]
112121pub 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