Spellauncher input example


#1

hello guys im new on rust programming .
im trying to write a simple program that takes word from input stdin and check the spell and respond the corect anwser if the word is wrong spelled.i did little search and i found a library “ispell”.
i wrote the program on my own knowlege but im getting error .any help can be so usefull for me.and i dont want just a correction on my program i need to know what is my problem exactly.tnx

extern crate ispell;

use ispell::SpellLauncher;
use std::io;

fn main(){
let mut checker = SpellLauncher::new()
.aspell()
.dictionary(“en_GB”)
.launch()
.unwrap();
let mut errors = stdin().read_line()

io::stdin().read_line(&mut errors);
for e in errors{
    println!("'{}' (pos: {}) is misspelled!", &e.misspelled, e.position);
    if !e.suggestions.is_empty() {
        println!("Maybe you meant '{}'?", &e.suggestions[0]);
    }
}

}


#2

The code you’ve posted is not complete so it’s hard to tell what problem you’re having just from the code. In general, you should probably explain the exact problem you’re having. Including the actual errors would help us help you also.

I would complete the code starting with passing a buffer to stdin().read_line() and work the problem from there.


#3

the error says in second one input must be iterable for running in for condition.so i figured out i must change the errors variable to integer not stirng .so this is far i got reach .

12 | let mut errors = Iterator;
| ^^^^^^^^ unresolved name
|
= help: trait Iterator cannot be used as an expression

error[E0277]: the trait bound std::string::String: std::iter::Iterator is not satisfied
–> src/main.rs:15:5
|
15 | for e in errors{
| ^ starting here…
16 | | println!("’{}’ (pos: {}) is misspelled!", &e.misspelled, e.position);
17 | | if !e.suggestions.is_empty() {
18 | | println!(“Maybe you meant ‘{}’?”, &e.suggestions[0]);
19 | | }
20 | | }
| |
^ …ending here: the trait std::iter::Iterator is not implemented for std::string::String
|
= note: std::string::String is not an iterator; maybe try calling .iter() or a similar method
= note: required by std::iter::IntoIterator::into_iter


#4

Is your code in a repo that we can read?


#5

I think the problem is you forget to run checker.check(...) to convert the string to errors:

Here “errors” don’t correspond to the errors but to a string read from the input. You probably want something like this (not tested):

let mut line = String::new();
io::stdin().read_line(&mut line).expect("Could not read line from stdin");
let errors = checkers.check(&line).expect("Error checking errors");
for e in errors { 
   ...
}

#6

the problem before is solved but now it says cant read the dictanary from /src/lib/aspel-0.60/ .so i checked there is no dict file there for reading.i download en_US dict and put that to directory so i tried that but same promlem again.and i tought my structure is the problem but i run the sample on git hub :


again that problem comes.

and this is the console result for compiling :

/home/babyjesus/.cargo/bin/cargo run --color=always --bin ddx
Compiling ddx v0.1.0 (file:///home/babyjesus/IdeaProjects/ddx)
Finished debug [unoptimized + debuginfo] target(s) in 0.52 secs
Running target/debug/ddx
Error: The file “/usr/lib/aspell-0.60/en_GB” can not be opened for reading.
thread ‘main’ panicked at ‘called Result::unwrap() on an Err value: Error { msg: “First line of ispell output doesn’t start with ‘@’, aborting”, variant: Protocol }’, /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:837
stack backtrace:
1: 0x5589def0987a - std::sys::imp::backtrace::tracing::imp::write::h3188f035833a2635
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
2: 0x5589def0d28f - std::panicking::default_hook::{{closure}}::h6385b6959a2dd25b
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:349
3: 0x5589def0ce8e - std::panicking::default_hook::he4f3b61755d7fa95
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:365
4: 0x5589def0d677 - std::panicking::rust_panic_with_hook::hf00b8130f73095ec
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:553
5: 0x5589def0d4b4 - std::panicking::begin_panic::h6227f62cb2cdaeb4
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:515
6: 0x5589def0d429 - std::panicking::begin_panic_fmt::h173eadd80ae64bec
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:499
7: 0x5589def0d3b7 - rust_begin_unwind
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:475
8: 0x5589def33b4d - core::panicking::panic_fmt::h3b2d1e30090844ff
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:69
9: 0x5589deeea662 - core::result::unwrap_failed::h641697322dac9b9b
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/macros.rs:29
10: 0x5589deee9b4d - <core::result::Result<T, E>>::unwrap::h25abb80ef05e9992
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:737
11: 0x5589deeebf9d - ddx::main::h4a48f83068e6b4cf
at /home/babyjesus/IdeaProjects/ddx/src/main.rs:5
12: 0x5589def1593a - __rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
13: 0x5589def0db76 - std::rt::lang_start::h65647f6e36cffdae
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:434
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:351
at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57
14: 0x5589deeec522 - main
15: 0x7f8470cfb290 - __libc_start_main
16: 0x5589deee95b9 - _start
17: 0x0 -

Process finished with exit code 101


#7

In this example it looks to the “en_GB” dictionary, not “en_US”. You probably want to change (or remove) the .dictionary("en_GB") line.