Struct SpellLauncher

Source
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 with british 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

Source

pub fn new() -> SpellLauncher

Creates a new spell checker with default options

Examples found in repository?
examples/timeout.rs (line 5)
4fn main() {
5    let checker = SpellLauncher::new()
6        .command("examples/sleep.sh")
7        .timeout(5)
8        .launch();
9    assert!(checker.is_err());
10    if let Err(err) = checker {
11        println!("{}", err);
12    }
13}
More examples
Hide additional examples
examples/dict.rs (line 5)
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}
examples/readme.rs (line 5)
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}
examples/simple.rs (line 23)
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}
Source

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?
examples/readme.rs (line 6)
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}
Source

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

Source

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)

Source

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.

Examples found in repository?
examples/timeout.rs (line 7)
4fn main() {
5    let checker = SpellLauncher::new()
6        .command("examples/sleep.sh")
7        .timeout(5)
8        .launch();
9    assert!(checker.is_err());
10    if let Err(err) = checker {
11        println!("{}", err);
12    }
13}
Source

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?
examples/timeout.rs (line 6)
4fn main() {
5    let checker = SpellLauncher::new()
6        .command("examples/sleep.sh")
7        .timeout(5)
8        .launch();
9    assert!(checker.is_err());
10    if let Err(err) = checker {
11        println!("{}", err);
12    }
13}
More examples
Hide additional examples
examples/readme.rs (line 7)
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}
examples/simple.rs (line 25)
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}
Source

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?
examples/readme.rs (line 8)
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
Hide additional examples
examples/simple.rs (line 24)
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}
Source

pub fn launch(&self) -> Result<SpellChecker>

Launch ispell (or aspell or hunspell) and return a SpellChecker

Examples found in repository?
examples/timeout.rs (line 8)
4fn main() {
5    let checker = SpellLauncher::new()
6        .command("examples/sleep.sh")
7        .timeout(5)
8        .launch();
9    assert!(checker.is_err());
10    if let Err(err) = checker {
11        println!("{}", err);
12    }
13}
More examples
Hide additional examples
examples/dict.rs (line 6)
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}
examples/readme.rs (line 9)
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}
examples/simple.rs (line 26)
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}

Trait Implementations§

Source§

impl Debug for SpellLauncher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.