Closed
Description
Hello world. Here is an example of code;
fn main() {
fn test() { println!("Testing !") }
let hm: HashMap<&str, fn()> = HashMap::from([("test", test)]);
hm.get("test").unwrap()();
}
Here is the output:
error[E0308]: mismatched types
--> src/main.rs:5:32
|
5 | let hm: HashMap<&str, fn()> = HashMap::from([("test", test)]);
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
| |
| expected due to this
|
= note: expected struct `HashMap<&str, fn()>`
found struct `HashMap<&str, fn() {test}>`
The issue with this output is that, for a newbie, it is very mysterious, it doesn't help to know what exactly is wrong or at least how to fix it.
The compiler should print a hint like: "try test as fn()
".
Thanks in advance !