1extern crate ispell;
6use ispell::{SpellLauncher, IspellError};
7
8fn display(errors: &[IspellError]) {
9 if errors.is_empty() {
10 println!("No error, congratulations!");
11 } else {
12 for e in errors {
13 print!("'{}' (at pos {}) is misspelled.", e.misspelled, e.position);
14 if !e.suggestions.is_empty() {
15 print!(" Maybe you meant '{}'?", e.suggestions[0]);
16 }
17 println!("");
18 }
19 }
20}
21
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}