An important fact that isn’t explicitly mentioned in the book is this requirement from the
If you are implementing
Ord, they must produce the same result.
This isn’t enforced by the type system (so you can’t rely on it for memory safety), but it is a documented requirement for all implementers of the
Borrowtrait. This means that if you have a
&stryou can hash both of them directly, without first converting them to have the same type.
Why are these invariants not enforced by the type system?