When hashing / eq-ing on a Vec, is it guaranteed that it depends only on (1) length of vector and (2) elements of vector ?

(In particular, I'm concerned that two vectors with same length, same elements, but different CAPACITY might end up different in the eyes of eq/hash).

alice
2
Yes, in fact they are implemented by passing on to the corresponding implementations for slices, where capacities are no longer relevant.

3 Likes

And this is guaranteed to remain true because `Vec<T>`

implements `Borrow<[T]>`

, and the `Borrow`

trait requires that:

In particular `Eq`

, `Ord`

and `Hash`

must be equivalent for borrowed and owned values: `x.borrow() == y.borrow()`

should give the same result as `x == y`

.

6 Likes

system
Closed
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.