pub struct SpellLauncher { /* private fields */ }
Expand description
Spell Launcher wizard (ah, ah). A builder for SpellChecker
.
Runs ispell
or one of its variant.
§Examples
- Launches
ispell
withbritish
dictionary:
use ispell::SpellLauncher;
let checker = SpellLauncher::new()
.dictionary("british")
.launch()
.unwrap();
- Launches
aspell
with french (France) language:
use ispell::SpellLauncher;
let checker = SpellLauncher::new()
.aspell()
.dictionary("fr_FR")
.launch()
.unwrap();
Implementations§
Source§impl SpellLauncher
impl SpellLauncher
Sourcepub fn new() -> SpellLauncher
pub fn new() -> SpellLauncher
Creates a new spell checker with default options
Examples found in repository?
More examples
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .launch()
7 .unwrap();
8
9 // "foobar" is not a valid word...
10 let errors = checker.check("foobar").unwrap();
11 println!("errors: {:?}", errors);
12 assert_eq!(errors.len(), 1);
13
14 // let's add it
15 checker.add_word("foobar").unwrap();
16 let errors = checker.check("foobar").unwrap();
17 println!("errors: {:?}", errors);
18 assert!(errors.is_empty());
19}
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .aspell()
7 .command("aspell")
8 .dictionary("en")
9 .launch()
10 .unwrap();
11 let errors = checker.check("A simpel test to to see if it detetcs typing errors").unwrap();
12 for e in errors {
13 println!("'{}' (pos: {}) is misspelled!", &e.misspelled, e.position);
14 if !e.suggestions.is_empty() {
15 println!("Maybe you meant '{}'?", &e.suggestions[0]);
16 }
17 }
18}
22fn main() {
23 let checker = SpellLauncher::new()
24 .dictionary("en_GB")
25 .command("hunspell")
26 .launch();
27 match checker {
28 Ok(mut checker) => {
29 let res = checker.check("test of a msitake").unwrap();
30 display(&res);
31 let res = checker.check("test without mistake (?)").unwrap();
32 display(&res);
33 let res = checker.check("Another test wiht a mistake").unwrap();
34 display(&res);
35 },
36 Err(err) => println!("Error: {}", err)
37 }
38}
Sourcepub fn aspell(&mut self) -> &mut SpellLauncher
pub fn aspell(&mut self) -> &mut SpellLauncher
Sets mode to aspell instead of ispell.
Will run aspell
as the command if it is not set
Examples found in repository?
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .aspell()
7 .command("aspell")
8 .dictionary("en")
9 .launch()
10 .unwrap();
11 let errors = checker.check("A simpel test to to see if it detetcs typing errors").unwrap();
12 for e in errors {
13 println!("'{}' (pos: {}) is misspelled!", &e.misspelled, e.position);
14 if !e.suggestions.is_empty() {
15 println!("Maybe you meant '{}'?", &e.suggestions[0]);
16 }
17 }
18}
Sourcepub fn hunspell(&mut self) -> &mut SpellLauncher
pub fn hunspell(&mut self) -> &mut SpellLauncher
Sets compatibility mode to hunspell instead of ispell.
Will run hunspell
as the command if it is not set
Sourcepub fn ispell(&mut self) -> &mut SpellLauncher
pub fn ispell(&mut self) -> &mut SpellLauncher
Sets compatibility mode to ispell
Will run ispell
as the command if it is not set
(default setting)
Sourcepub fn timeout(&mut self, timeout: u64) -> &mut SpellLauncher
pub fn timeout(&mut self, timeout: u64) -> &mut SpellLauncher
Sets the timeout when checking ispell
If the spawned process takes longer than this timeout to answer to a query, it will be killed and an error will be returned, preventing your program from freezing indefinitely.
The timeout is set in milliseconds, and is 1000 (a second) by default.
Sourcepub fn command<S: Into<String>>(&mut self, command: S) -> &mut SpellLauncher
pub fn command<S: Into<String>>(&mut self, command: S) -> &mut SpellLauncher
Set the name of the command to run
By default, it inferred from the mode (which is ispell
by default).
Unless you want to run a specific (ispell-compatible) command, you shouldn’t use this method directly, but rather
use the aspell
or hunspell
methods, since this also allow the the library to know which actual program
is runned and to set encoding options accordingly.
Examples found in repository?
More examples
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .aspell()
7 .command("aspell")
8 .dictionary("en")
9 .launch()
10 .unwrap();
11 let errors = checker.check("A simpel test to to see if it detetcs typing errors").unwrap();
12 for e in errors {
13 println!("'{}' (pos: {}) is misspelled!", &e.misspelled, e.position);
14 if !e.suggestions.is_empty() {
15 println!("Maybe you meant '{}'?", &e.suggestions[0]);
16 }
17 }
18}
22fn main() {
23 let checker = SpellLauncher::new()
24 .dictionary("en_GB")
25 .command("hunspell")
26 .launch();
27 match checker {
28 Ok(mut checker) => {
29 let res = checker.check("test of a msitake").unwrap();
30 display(&res);
31 let res = checker.check("test without mistake (?)").unwrap();
32 display(&res);
33 let res = checker.check("Another test wiht a mistake").unwrap();
34 display(&res);
35 },
36 Err(err) => println!("Error: {}", err)
37 }
38}
Sourcepub fn dictionary<S: Into<String>>(&mut self, lang: S) -> &mut SpellLauncher
pub fn dictionary<S: Into<String>>(&mut self, lang: S) -> &mut SpellLauncher
Determine the dictionary that should be used.
Note that ispell
, hunspell
and aspell
have different naming schemes:
ispell
accepts full names, e.g. “american”, “british”, “french”, …hunspell
accepts unicode language codes, e.g. “fr_FR”, “en_GB”, …aspell
accepts both.
§Example
use ispell::SpellLauncher;
let checker = SpellLauncher::new()
.aspell()
.dictionary("en_GB")
.launch()
.unwrap();
Examples found in repository?
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .aspell()
7 .command("aspell")
8 .dictionary("en")
9 .launch()
10 .unwrap();
11 let errors = checker.check("A simpel test to to see if it detetcs typing errors").unwrap();
12 for e in errors {
13 println!("'{}' (pos: {}) is misspelled!", &e.misspelled, e.position);
14 if !e.suggestions.is_empty() {
15 println!("Maybe you meant '{}'?", &e.suggestions[0]);
16 }
17 }
18}
More examples
22fn main() {
23 let checker = SpellLauncher::new()
24 .dictionary("en_GB")
25 .command("hunspell")
26 .launch();
27 match checker {
28 Ok(mut checker) => {
29 let res = checker.check("test of a msitake").unwrap();
30 display(&res);
31 let res = checker.check("test without mistake (?)").unwrap();
32 display(&res);
33 let res = checker.check("Another test wiht a mistake").unwrap();
34 display(&res);
35 },
36 Err(err) => println!("Error: {}", err)
37 }
38}
Sourcepub fn launch(&self) -> Result<SpellChecker>
pub fn launch(&self) -> Result<SpellChecker>
Launch ispell
(or aspell
or hunspell
) and return a SpellChecker
Examples found in repository?
More examples
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .launch()
7 .unwrap();
8
9 // "foobar" is not a valid word...
10 let errors = checker.check("foobar").unwrap();
11 println!("errors: {:?}", errors);
12 assert_eq!(errors.len(), 1);
13
14 // let's add it
15 checker.add_word("foobar").unwrap();
16 let errors = checker.check("foobar").unwrap();
17 println!("errors: {:?}", errors);
18 assert!(errors.is_empty());
19}
4fn main() {
5 let mut checker = SpellLauncher::new()
6 .aspell()
7 .command("aspell")
8 .dictionary("en")
9 .launch()
10 .unwrap();
11 let errors = checker.check("A simpel test to to see if it detetcs typing errors").unwrap();
12 for e in errors {
13 println!("'{}' (pos: {}) is misspelled!", &e.misspelled, e.position);
14 if !e.suggestions.is_empty() {
15 println!("Maybe you meant '{}'?", &e.suggestions[0]);
16 }
17 }
18}
22fn main() {
23 let checker = SpellLauncher::new()
24 .dictionary("en_GB")
25 .command("hunspell")
26 .launch();
27 match checker {
28 Ok(mut checker) => {
29 let res = checker.check("test of a msitake").unwrap();
30 display(&res);
31 let res = checker.check("test without mistake (?)").unwrap();
32 display(&res);
33 let res = checker.check("Another test wiht a mistake").unwrap();
34 display(&res);
35 },
36 Err(err) => println!("Error: {}", err)
37 }
38}