@@ -22,6 +22,7 @@ use ops::Drop;
22
22
use kinds:: { Freeze , Send } ;
23
23
use clone:: { Clone , DeepClone } ;
24
24
use cell:: RefCell ;
25
+ use cmp:: { Eq , TotalEq , Ord , TotalOrd , Ordering } ;
25
26
26
27
struct RcBox < T > {
27
28
value : T ,
@@ -80,6 +81,60 @@ impl<T> Rc<T> {
80
81
pub fn borrow < ' r > ( & ' r self ) -> & ' r T {
81
82
unsafe { & ( * self . ptr ) . value }
82
83
}
84
+
85
+ /// Determine if two reference-counted pointers point to the same object
86
+ #[ inline]
87
+ pub fn ptr_eq ( & self , other : & Rc < T > ) -> bool {
88
+ self . ptr == other. ptr
89
+ }
90
+ }
91
+
92
+ impl < T : Eq > Eq for Rc < T > {
93
+ #[ inline]
94
+ fn eq ( & self , other : & Rc < T > ) -> bool {
95
+ unsafe { ( * self . ptr ) . value == ( * other. ptr ) . value }
96
+ }
97
+
98
+ #[ inline]
99
+ fn ne ( & self , other : & Rc < T > ) -> bool {
100
+ unsafe { ( * self . ptr ) . value != ( * other. ptr ) . value }
101
+ }
102
+ }
103
+
104
+ impl < T : TotalEq > TotalEq for Rc < T > {
105
+ #[ inline]
106
+ fn equals ( & self , other : & Rc < T > ) -> bool {
107
+ unsafe { ( * self . ptr ) . value . equals ( & ( * other. ptr ) . value ) }
108
+ }
109
+ }
110
+
111
+ impl < T : Ord > Ord for Rc < T > {
112
+ #[ inline]
113
+ fn lt ( & self , other : & Rc < T > ) -> bool {
114
+ unsafe { ( * self . ptr ) . value < ( * other. ptr ) . value }
115
+ }
116
+
117
+ #[ inline]
118
+ fn le ( & self , other : & Rc < T > ) -> bool {
119
+ unsafe { ( * self . ptr ) . value <= ( * other. ptr ) . value }
120
+ }
121
+
122
+ #[ inline]
123
+ fn ge ( & self , other : & Rc < T > ) -> bool {
124
+ unsafe { ( * self . ptr ) . value >= ( * other. ptr ) . value }
125
+ }
126
+
127
+ #[ inline]
128
+ fn gt ( & self , other : & Rc < T > ) -> bool {
129
+ unsafe { ( * self . ptr ) . value > ( * other. ptr ) . value }
130
+ }
131
+ }
132
+
133
+ impl < T : TotalOrd > TotalOrd for Rc < T > {
134
+ #[ inline]
135
+ fn cmp ( & self , other : & Rc < T > ) -> Ordering {
136
+ unsafe { ( * self . ptr ) . value . cmp ( & ( * other. ptr ) . value ) }
137
+ }
83
138
}
84
139
85
140
impl < T > Clone for Rc < T > {
0 commit comments