Using HashMap on struct that doesn't derive Hash and Eq


#1

So, basically I want to have an HashMap<String, opengl_graphics::Texture>.
Why? Because opengl_graphics::Texture doesn’t have any function to get its String name and having an HashMap seems a good idea. Though there’s a problem, opengl_graphics::Texture does not derive Hash nor Eq
What’s my best shot here?
Thanks!


#2

Wouldn’t it be a HashMap<String, opengl_graphics::Texture> in this case? I don’t see how making your data the key can be useful…


#3

Yeah you’re right, I changed it, the String is the key.


#4

The value type of a HashMap doesn’t have to be Hash or Eq, only the key, so this should just work.


#5

I must have screwed up when using insert. Damn me.