We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
std::ptr::eq()
1 parent 4b5728d commit 7f39a45Copy full SHA for 7f39a45
src/language/equality.md
@@ -70,6 +70,21 @@ fn main() {
70
}
71
```
72
73
+There is no direct equivalence to reference equality in Rust, since not everything is a reference.
74
+However, when you have two references, you can check for their reference equality with `std::ptr::eq()`
75
+
76
+```rust
77
+fn main() {
78
+ let a = 1;
79
+ let b = 1;
80
+ println!("{}", a == b); // true
81
+ println!("{}", std::ptr::eq(&a, &b)); // false
82
+ println!("{}", std::ptr::eq(&a, &a)); // true
83
+}
84
+```
85
86
+Another way to compare for reference equality is to convert the references to raw pointers and compare them using `==`.
87
88
See also:
89
90
- [`Eq`][eq.rs] for a stricter version of `PartialEq`.
0 commit comments