9999
100100use fmt;
101101use marker:: { Sized , Unpin } ;
102+ use cmp:: { self , PartialEq , PartialOrd } ;
102103use ops:: { Deref , DerefMut , Receiver , CoerceUnsized , DispatchFromDyn } ;
103104
104105/// A pinned pointer.
@@ -112,16 +113,59 @@ use ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
112113/// [`Unpin`]: ../../std/marker/trait.Unpin.html
113114/// [`pin` module]: ../../std/pin/index.html
114115//
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`.
117119#[ stable( feature = "pin" , since = "1.33.0" ) ]
118120#[ fundamental]
119121#[ repr( transparent) ]
120- #[ derive( Copy , Clone , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
122+ #[ derive( Copy , Clone , Hash , Eq , Ord ) ]
121123pub struct Pin < P > {
122124 pointer : P ,
123125}
124126
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+
125169impl < P : Deref > Pin < P >
126170where
127171 P :: Target : Unpin ,
0 commit comments