99
99
100
100
use fmt;
101
101
use marker:: { Sized , Unpin } ;
102
+ use cmp:: { self , PartialEq , PartialOrd } ;
102
103
use ops:: { Deref , DerefMut , Receiver , CoerceUnsized , DispatchFromDyn } ;
103
104
104
105
/// A pinned pointer.
@@ -112,16 +113,59 @@ use ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
112
113
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
113
114
/// [`pin` module]: ../../std/pin/index.html
114
115
//
115
- // Note: the derives below are allowed because they all only use `&P`, so they
116
- // cannot move the value behind `pointer`.
116
+ // Note: the derives below, and the explicit `PartialEq` and `PartialOrd`
117
+ // implementations, are allowed because they all only use `&P`, so they cannot move
118
+ // the value behind `pointer`.
117
119
#[ stable( feature = "pin" , since = "1.33.0" ) ]
118
120
#[ fundamental]
119
121
#[ repr( transparent) ]
120
- #[ derive( Copy , Clone , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
122
+ #[ derive( Copy , Clone , Hash , Eq , Ord ) ]
121
123
pub struct Pin < P > {
122
124
pointer : P ,
123
125
}
124
126
127
+ #[ stable( feature = "pin_partialeq_partialord_impl_applicability" , since = "1.34.0" ) ]
128
+ impl < P , Q > PartialEq < Pin < Q > > for Pin < P >
129
+ where
130
+ P : PartialEq < Q > ,
131
+ {
132
+
133
+ fn eq ( & self , other : & Pin < Q > ) -> bool {
134
+ self . pointer == other. pointer
135
+ }
136
+
137
+ fn ne ( & self , other : & Pin < Q > ) -> bool {
138
+ self . pointer != other. pointer
139
+ }
140
+ }
141
+
142
+ #[ stable( feature = "pin_partialeq_partialord_impl_applicability" , since = "1.34.0" ) ]
143
+ impl < P , Q > PartialOrd < Pin < Q > > for Pin < P >
144
+ where
145
+ P : PartialOrd < Q > ,
146
+ {
147
+
148
+ fn partial_cmp ( & self , other : & Pin < Q > ) -> Option < cmp:: Ordering > {
149
+ self . pointer . partial_cmp ( & other. pointer )
150
+ }
151
+
152
+ fn lt ( & self , other : & Pin < Q > ) -> bool {
153
+ self . pointer < other. pointer
154
+ }
155
+
156
+ fn le ( & self , other : & Pin < Q > ) -> bool {
157
+ self . pointer <= other. pointer
158
+ }
159
+
160
+ fn gt ( & self , other : & Pin < Q > ) -> bool {
161
+ self . pointer > other. pointer
162
+ }
163
+
164
+ fn ge ( & self , other : & Pin < Q > ) -> bool {
165
+ self . pointer >= other. pointer
166
+ }
167
+ }
168
+
125
169
impl < P : Deref > Pin < P >
126
170
where
127
171
P :: Target : Unpin ,
0 commit comments