-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a function to compare pointers and references for equality #1155
Comments
The |
At the moment I use |
@Columbus240 You can implement ptr_eq or compare raw pointers (comparing |
I noticed that too, I misunderstood the concept of raw pointers in Rust, this is the first time I use them. |
The ref_eq crate now provides this (implementation taken from an old version that was deleted from the standard library) |
rust-lang/rust#35992 implements this. |
Currently, Rust lacks a nice way to compare two values of type
&T
orCell<T>
for identity of references (as opposed to identity of the stored values). With a, b having type&T
, one has to writea as *const _ == a as *const _
, which is not exactly discoverable nor nice to look at.We (eddyb, kimundi and me) discussed this on IRC, kimundi made the following proposal:
Thanks to coercions, in the above scenario, we can now write "ptr_eq(a, b)". eddyb was opposed to a function providing "reference" equality on
&T
, due to the difference of references in Rust and other languages (in particular, involving zero-sized types).I think some nice way of comparing pointers (references) for equality should be provided, that does not force the user to manually write down a cast to a "dangerous" raw pointer (though of course the usage above is completely safe).
The text was updated successfully, but these errors were encountered: