@@ -59,6 +59,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
59
59
let mut keys_iter_init = Vec :: new ( ) ;
60
60
let mut iter_init = Vec :: new ( ) ;
61
61
let mut entry = Vec :: new ( ) ;
62
+ let mut cmp_init = Vec :: new ( ) ;
62
63
63
64
for ( index, variant) in en. variants . iter ( ) . enumerate ( ) {
64
65
let var = & variant. ident ;
@@ -85,6 +86,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
85
86
iter_init. push ( quote ! ( ( #ident:: #var, #name) ) ) ;
86
87
names. push ( name. clone ( ) ) ;
87
88
entry. push ( quote ! ( option_to_entry( #name, key) ) ) ;
89
+ cmp_init. push ( quote ! ( ( #index, #name) ) ) ;
88
90
}
89
91
90
92
let count = en. variants . len ( ) ;
@@ -174,6 +176,18 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
174
176
quote ! ( )
175
177
} ;
176
178
179
+ let self_cmp_iter_init = quote ! { {
180
+ let [ #( #names) , * ] = & self . data;
181
+ let init: [ ( usize , & Option <V >) ; #count] = [ #( #cmp_init) , * ] ;
182
+ #iterator:: flat_map( #into_iter( init) , |( k, v) | #option:: Some ( ( k, #option:: as_ref( v) ?) ) )
183
+ } } ;
184
+
185
+ let other_cmp_iter_init = quote ! { {
186
+ let [ #( #names) , * ] = & other. data;
187
+ let init: [ ( usize , & Option <V >) ; #count] = [ #( #cmp_init) , * ] ;
188
+ #iterator:: flat_map( #into_iter( init) , |( k, v) | #option:: Some ( ( k, #option:: as_ref( v) ?) ) )
189
+ } } ;
190
+
177
191
Ok ( quote ! {
178
192
const #const_wrapper: ( ) = {
179
193
#[ repr( transparent) ]
@@ -226,53 +240,35 @@ pub(crate) fn implement(cx: &Ctxt<'_>, en: &DataEnum) -> Result<TokenStream, ()>
226
240
impl <V > #partial_ord for Storage <V > where V : #partial_ord {
227
241
#[ inline]
228
242
fn partial_cmp( & self , other: & Self ) -> Option <#ordering> {
229
- #partial_ord :: partial_cmp( & self . data , & other . data )
243
+ #iterator :: partial_cmp( #self_cmp_iter_init , #other_cmp_iter_init )
230
244
}
231
245
232
246
#[ inline]
233
247
fn lt( & self , other: & Self ) -> bool {
234
- #partial_ord :: lt( & self . data , & other . data )
248
+ #iterator :: lt( #self_cmp_iter_init , #other_cmp_iter_init )
235
249
}
236
250
237
251
#[ inline]
238
252
fn le( & self , other: & Self ) -> bool {
239
- #partial_ord :: le( & self . data , & other . data )
253
+ #iterator :: le( #self_cmp_iter_init , #other_cmp_iter_init )
240
254
}
241
255
242
256
#[ inline]
243
257
fn gt( & self , other: & Self ) -> bool {
244
- #partial_ord :: gt( & self . data , & other . data )
258
+ #iterator :: gt( #self_cmp_iter_init , #other_cmp_iter_init )
245
259
}
246
260
247
261
#[ inline]
248
262
fn ge( & self , other: & Self ) -> bool {
249
- #partial_ord :: ge( & self . data , & other . data )
263
+ #iterator :: ge( #self_cmp_iter_init , #other_cmp_iter_init )
250
264
}
251
265
}
252
266
253
267
#[ automatically_derived]
254
268
impl <V > #ord for Storage <V > where V : #ord {
255
269
#[ inline]
256
270
fn cmp( & self , other: & Self ) -> #ordering {
257
- #ord:: cmp( self , other)
258
- }
259
-
260
- #[ inline]
261
- fn max( self , other: Self ) -> Self {
262
- Self { data: #ord:: max( self . data, other. data) }
263
- }
264
-
265
- #[ inline]
266
- fn min( self , other: Self ) -> Self {
267
- Self { data: #ord:: min( self . data, other. data) }
268
- }
269
-
270
- #[ inline]
271
- fn clamp( self , min: Self , max: Self ) -> Self
272
- where
273
- Self : #partial_ord<Self >
274
- {
275
- Self { data: #ord:: clamp( self . data, min. data, max. data) }
271
+ #iterator:: cmp( #self_cmp_iter_init, #other_cmp_iter_init)
276
272
}
277
273
}
278
274
0 commit comments