In JavaScript, one can compare/find objects like this:
let foo = {}
let bar = foo
[foo].includes(bar) // true
It's a fast operation, because as far as I know, JavaSscript stores some hidden identifier (memory address?) for every object and just compares them. Rust, on the other hand seems to require implementing the Eq
trait which compares every single field including those of every underlying data structure. I can imagine that this may be very, very slow, for such a performant language as Rust, so I guess I am missing something. Where am I wrong? Also, can Rust compare objects in a safe manner by their memory address?
To rephrase my question, I want to know if two references point to the same object.