@@ -10,6 +10,8 @@ mod kw {
10
10
syn:: custom_keyword!( MAX ) ;
11
11
syn:: custom_keyword!( ENCODABLE ) ;
12
12
syn:: custom_keyword!( custom) ;
13
+ syn:: custom_keyword!( ORD_IMPL ) ;
14
+ syn:: custom_keyword!( off) ;
13
15
}
14
16
15
17
#[ derive( Debug ) ]
@@ -42,6 +44,7 @@ impl Parse for Newtype {
42
44
let mut max = None ;
43
45
let mut consts = Vec :: new ( ) ;
44
46
let mut encodable = true ;
47
+ let mut ord = true ;
45
48
46
49
// Parse an optional trailing comma
47
50
let try_comma = || -> Result < ( ) > {
@@ -100,6 +103,15 @@ impl Parse for Newtype {
100
103
continue ;
101
104
}
102
105
106
+ if body. lookahead1 ( ) . peek ( kw:: ORD_IMPL ) {
107
+ body. parse :: < kw:: ORD_IMPL > ( ) ?;
108
+ body. parse :: < Token ! [ =] > ( ) ?;
109
+ body. parse :: < kw:: off > ( ) ?;
110
+ try_comma ( ) ?;
111
+ ord = false ;
112
+ continue ;
113
+ }
114
+
103
115
// We've parsed everything that the user provided, so we're done
104
116
if body. is_empty ( ) {
105
117
break ;
@@ -137,6 +149,16 @@ impl Parse for Newtype {
137
149
quote ! { }
138
150
} ;
139
151
152
+ let default_derives = if ord {
153
+ quote ! {
154
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord ) ]
155
+ }
156
+ } else {
157
+ quote ! {
158
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
159
+ }
160
+ } ;
161
+
140
162
let debug_impl = match debug_format {
141
163
DebugFormat :: Custom => quote ! { } ,
142
164
DebugFormat :: Format ( format) => {
@@ -152,7 +174,8 @@ impl Parse for Newtype {
152
174
153
175
Ok ( Self ( quote ! {
154
176
#( #attrs) *
155
- #[ derive( Clone , Copy , PartialEq , Eq , Hash , PartialOrd , Ord , #( #derive_paths) , * ) ]
177
+ #default_derives
178
+ #[ derive( #( #derive_paths) , * ) ]
156
179
#[ rustc_layout_scalar_valid_range_end( #max) ]
157
180
#vis struct #name {
158
181
private: u32 ,
0 commit comments