I want to store a function inside a Hashmap in rust, but i dont know how to "get" it and call it at another location. Here's what ive tried
type Ihello = fn() -> String;
fn main() {
use std::collections::HashMap;
let mut mapp: HashMap<String, Ihello> = HashMap::new();
mapp.insert(
"hello".to_string(),
hello
);
let hello_string = "hello".to_string();
let hello: Option<&Ihello> = book_reviews.get(&hello_string);
}
fn hello() -> String {
String::from("HELLOHELLOHELLO")
}
I want to "call" the hello function later on, is there any way to do it? or is there a alterative way to do this?