Hash/Eq on type: `for<'a> fn(&'a u32)`


Is there a reason why Hash and Eq are not implemented for function which have a parameter with a lifetime valid for any lifetime.

E.g. for <'a> fn(&'a u32) or short fn(&u32) does not implement Hash/Eq

I have a number of validation function, which are meant to be defined statically (e.g. through a macro, outside of the crate). And I intended to store them in a HashSet, as it is quite likely that the same function is added multiple times.


a workaround is to use a HashMap<usize, fn(&u32)> (or whatever your function types is) and to fill it like map.insert(func as usize, func).


Check out the discussion in Is there any plan to implement basic traits on function pointers that don’t take by value? I think the status as of January was there isn’t a way to express these impls in general in the type system so it would need to be a special case in the compiler, which may happen at some point if someone feels strongly enough to implement it, or it may wait for a new language feature to make things easier.