I have a situation where I need to compare if a
u32 holds the same value as a
usize. While it would be very convenient in this case if Rust provided such comparisons out of the box, I understand that some folks are concerned about performance gotchas (comparing an
i64 with a
u64 would require both a sign check and a comparison at the CPU level), and others believe that disallowing heterogeneous comparisons catches bugs and prevents more headaches than it causes.
Either way, I was surprised that I have not been able to find a crate that allows for easy comparison of heterogeneous integer types and automatically does the right thing. (E.g., losslessly promotes one to the other where possible, falling back to a sign check and comparison where necessary.)
Does such a crate exist?