I want to have an extendable dictionary linking together Object
with a &'static str
inside my library. HashMap
seems like the right data structure for this, but how do I make it global, initialised on declaration and mutable?
So something like this:
use std::collections::HashMap;
enum Object { A, B, C }
const OBJECT_STR: &'static [&'static str] = &[ "a", "b", "c" ];
static mut word_map: HashMap<&'static str, Object> = {
let mut m = HashMap::new();
m.insert(OBJECT_STR[0], Object::A);
m.insert(OBJECT_STR[1], Object::B);
m.insert(OBJECT_STR[2], Object::C);
m
};
impl Object {
...
}