That’s entirely dependent on the struct’s Hash implmentation; I don’t think #[derive(Hash)] makes any such assurance.
This already exists:
match foo {
"foo" => ..
}
IIRC this just does the obvious O(n) comparison. Using a hashmap for such a purpose is a bad idea: hashing will usually be slower than checking by equality anyways, and if your match is so big that a hashmap actually nets you a performance gain… your match is too big. A const HashMap is a good idea, but it should definitely not be generated by a match.
IIRC Java doesn’t use a hashmap to switch on strings but compiles it to a sequence of invokevirtuals, ifeqs, and gotos to emulate fall-through. It does do this for switching on enums, because the ordinal (a.k.a discriminant) of an enum is not fixed at compile time, because Java is linked at runtime. (Mind, I just ran example code through a disassembler so I could be completely wrong!)