I don't know detail about rust compiler, but, does rustc make some optimization to this constants rule checking?, I know vector does allocate on heap, if compiler does nothing about it then there'll be heap alloc at every api calls, right?, do I have to move it into constant/static?
Sometimes LLVM will be smart enough to optimise out Vec's allocation, but it's not guaranteed.
If you use a normal array which never gets modified, the compiler should automatically promote it to a const. That way you aren't setting aside memory for the array and populating it every time the function is called, and you don't need to explicitly write out the array's type like you would if it were a static or const variable.
Another option is to use the phf crate'sSet type to create an immutable, static lookup table which will give you really fast lookups.