I have some code in src/main.rs, including pub fn display(word: &str, guesses: &str) -> String { ... }
(it runs fine with cargo run
).
I have
[package]
name = "hangman"
version = "0.1.0"
edition = "2021"
in Cargo.toml
and I have
use hangman::*;
#[test]
fn test_display() {
assert_eq!(display("banana", ""), String::from("_ _ _ _ _ _"))
}
in tests/hangman.rs
When I run cargo test
I get the following errors:
Compiling hangman v0.1.0 (/home/feature/projects/hangman)
error[E0432]: unresolved import `hangman`
--> tests/hangman.rs:2:5
|
2 | use hangman::*;
| ^^^^^^^ use of undeclared crate or module `hangman`
error[E0425]: cannot find function `display` in this scope
--> tests/hangman.rs:5:16
|
5 | assert_eq!(display("banana", ""), String::from("_ _ _ _ _ _"))
| ^^^^^^^ not found in this scope
Some errors have detailed explanations: E0425, E0432.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `hangman` due to 2 previous errors
Why is hangman undeclared if it's named as such in Cargo.toml? Is there another place I need to declare it?