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