Is the hash map immutable? If so, look at the rust-phf crate.
Rust Programming
You may be able to use something like lazy_static.
I heard about this, but I wasn't sure it was the right way. Or if Rust developers just straight up avoid situations like this.
lazy_static was the standard way as far as I'm concerned until this month. OnceCell or OnceLock should fill this role now.
I generally avoid this situation. At best I'll create an Rc<HashMap<T, U>> to pass around. I find that having a need for a static variable can be an indication of bad design. It often makes the code that depends on it untestable.
Just make a function that match
es string and outputs your colors. It’ll be faster and easier than any extra crate.
The thing is, I also want to query all possible colors. And that would then be in a different function so I'd have to change two functions whenever I add a new color and I don't like that.
Then make a vector of colors, and make a function that match
es string to index in that vector