File tree Expand file tree Collapse file tree 1 file changed +28
-14
lines changed
Expand file tree Collapse file tree 1 file changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -54,21 +54,35 @@ impl PartialOrd for Citation {
5454
5555<details >
5656
57- ` PartialEq ` can be implemented between different types, but ` Eq ` cannot, because
58- it is reflexive:
57+ - ` PartialEq ` can be implemented between different types, but ` Eq ` cannot,
58+ because it is reflexive:
5959
60- ``` rust,editable
61- struct Key {
62- id: u32,
63- metadata: Option<String>,
64- }
65- impl PartialEq<u32> for Key {
66- fn eq(&self, other: &u32) -> bool {
67- self.id == *other
68- }
69- }
70- ```
60+ ``` rust,editable
61+ struct Key {
62+ id: u32,
63+ metadata: Option<String>,
64+ }
65+ impl PartialEq<u32> for Key {
66+ fn eq(&self, other: &u32) -> bool {
67+ self.id == *other
68+ }
69+ }
70+ ```
71+
72+ - In practice, it's common to derive these traits, but uncommon to implement
73+ them.
74+
75+ - When comparing references in Rust, it will will compare the value of the
76+ things pointed to, it will NOT compare the references themselves. That means
77+ that references to two different things can compare as equal if the values
78+ pointed to are the same:
7179
72- In practice, it's common to derive these traits, but uncommon to implement them.
80+ ``` rust,editable
81+ fn main() {
82+ let a = "Hello";
83+ let b = String::from("Hello");
84+ assert_eq!(a, b);
85+ }
86+ ```
7387
7488</details >
You can’t perform that action at this time.
0 commit comments