@@ -22,6 +22,7 @@ use ops::Drop;
2222use kinds:: { Freeze , Send } ;
2323use clone:: { Clone , DeepClone } ;
2424use cell:: RefCell ;
25+ use cmp:: { Eq , TotalEq , Ord , TotalOrd , Ordering } ;
2526
2627struct RcBox < T > {
2728 value : T ,
@@ -80,6 +81,60 @@ impl<T> Rc<T> {
8081 pub fn borrow < ' r > ( & ' r self ) -> & ' r T {
8182 unsafe { & ( * self . ptr ) . value }
8283 }
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+ }
83138}
84139
85140impl < T > Clone for Rc < T > {
0 commit comments