Unresolved import `unicode_reverse`

Hi, I’m trying the Rust “Reverse String” exercise, but getting the error below. I’m using the online editor, and the unicode_reverse is listed here, so shouldn’t it be available? rust-test-runner/local-registry/Cargo.toml at main · exercism/rust-test-runner · GitHub

My code:

use unicode_reverse::reverse_grapheme_clusters_in_place;

pub fn reverse(input: &str) -> String {
    reverse_grapheme_clusters_in_place(&mut input)
}

The error:

   Compiling reverse_string v1.2.0 (exercism-iteration)
error[E0432]: unresolved import `unicode_reverse`
 --> src/lib.rs:1:5
  |
1 | use unicode_reverse::reverse_grapheme_clusters_in_place;
  |     ^^^^^^^^^^^^^^^ use of undeclared crate or module `unicode_reverse`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `reverse_string` due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `reverse_string` due to 1 previous error

Said on discord that I guessed this was done to encourage learners to solve the exercise themselves.
@senekor can probably give the definitive answer.

Did you cargo add unicode-reverse?

Or if you’re using the online editor, Cargo.toml should contain something like this:

[dependencies]
unicode-reverse = "*"

Yes, I’m using the online editor. That’s why I’m confused as to why it’s saying it’s undeclared when it should be declared by the editor already?

Dependencies need to be added explicitly by your submission. The list of dependencies you linked to are only the ones that are available in the test runner, you still need to add

[dependencies]
unicode-reverse = "*"

to your own Cargo.toml.

Thank you! I just finally saw the cargo.toml tab in the editor (spent a half hour last night looking for a cargo.toml to edit somewhere in the editor, but I must have been tired).

Thanks again.

1 Like