@@ -73,7 +73,8 @@ fn try_message(input: TokenStream) -> Result<TokenStream> {
73
73
bail ! ( "message {} has fields with duplicate tags" , ident) ;
74
74
}
75
75
76
- let dummy_const = Ident :: new ( format ! ( "_IMPL_MESSAGE_FOR_{}" , ident) ) ;
76
+ // Put impls in a special module, so that 'extern crate' can be used.
77
+ let module = Ident :: new ( format ! ( "{}_MESSAGE" , ident) ) ;
77
78
78
79
let encoded_len = fields. iter ( )
79
80
. map ( |& ( ref field_ident, ref field) | {
@@ -115,13 +116,11 @@ fn try_message(input: TokenStream) -> Result<TokenStream> {
115
116
} ;
116
117
117
118
let expanded = quote ! {
118
- #[ allow( non_upper_case_globals, unused_attributes) ]
119
- const #dummy_const: ( ) = {
120
-
119
+ #[ allow( non_snake_case, unused_attributes) ]
120
+ mod #module {
121
121
extern crate prost as _prost;
122
122
extern crate bytes as _bytes;
123
123
124
- #[ automatically_derived]
125
124
impl _prost:: Message for #ident {
126
125
fn encode_raw<B >( & self , buf: & mut B ) where B : _bytes:: BufMut {
127
126
#( #encode) *
@@ -141,17 +140,16 @@ fn try_message(input: TokenStream) -> Result<TokenStream> {
141
140
}
142
141
}
143
142
144
- #[ automatically_derived]
145
143
impl Default for #ident {
146
144
fn default ( ) -> #ident {
147
145
#ident {
148
146
#( #default ) *
149
147
}
150
148
}
151
149
}
152
- } ;
153
150
154
- #methods
151
+ #methods
152
+ } ;
155
153
} ;
156
154
157
155
expanded. parse :: < TokenStream > ( ) . map_err ( |err| Error :: from ( format ! ( "{:?}" , err) ) )
@@ -196,20 +194,20 @@ pub fn enumeration(input: TokenStream) -> TokenStream {
196
194
197
195
let default = variants[ 0 ] . 0 . clone ( ) ;
198
196
199
- let dummy_const = Ident :: new ( format ! ( "_IMPL_ENUMERATION_FOR_{}" , ident) ) ;
197
+ // Put impls in a special module, so that 'extern crate' can be used.
198
+ let module = Ident :: new ( format ! ( "{}_ENUMERATION" , ident) ) ;
200
199
let is_valid = variants. iter ( ) . map ( |& ( _, ref value) | quote ! ( #value => true ) ) ;
201
200
let from = variants. iter ( ) . map ( |& ( ref variant, ref value) | quote ! ( #value => :: std:: option:: Option :: Some ( #ident:: #variant) ) ) ;
202
201
203
202
let is_valid_doc = format ! ( "Returns `true` if `value` is a variant of `{}`." , ident) ;
204
203
let from_i32_doc = format ! ( "Converts an `i32` to a `{}`, or `None` if `value` is not a valid variant." , ident) ;
205
204
206
205
let expanded = quote ! {
207
- #[ allow( non_upper_case_globals , unused_attributes) ]
208
- const #dummy_const : ( ) = {
206
+ #[ allow( non_snake_case , unused_attributes) ]
207
+ mod #module {
209
208
extern crate bytes as _bytes;
210
209
extern crate prost as _prost;
211
210
212
- #[ automatically_derived]
213
211
impl #ident {
214
212
215
213
#[ doc=#is_valid_doc]
@@ -229,14 +227,12 @@ pub fn enumeration(input: TokenStream) -> TokenStream {
229
227
}
230
228
}
231
229
232
- #[ automatically_derived]
233
230
impl :: std:: default :: Default for #ident {
234
231
fn default ( ) -> #ident {
235
232
#ident:: #default
236
233
}
237
234
}
238
235
239
- #[ automatically_derived]
240
236
impl :: std:: convert:: From <#ident> for i32 {
241
237
fn from( value: #ident) -> i32 {
242
238
value as i32
@@ -296,7 +292,8 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream> {
296
292
panic ! ( "invalid oneof {}: variants have duplicate tags" , ident) ;
297
293
}
298
294
299
- let dummy_const = Ident :: new ( format ! ( "_IMPL_ONEOF_FOR_{}" , ident) ) ;
295
+ // Put impls in a special module, so that 'extern crate' can be used.
296
+ let module = Ident :: new ( format ! ( "{}_ONEOF" , ident) ) ;
300
297
301
298
let encode = fields. iter ( ) . map ( |& ( ref variant_ident, ref field) | {
302
299
let encode = field. encode ( & Ident :: new ( "*value" ) ) ;
@@ -320,8 +317,8 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream> {
320
317
} ) ;
321
318
322
319
let expanded = quote ! {
323
- #[ allow( non_upper_case_globals , unused_attributes) ]
324
- const #dummy_const : ( ) = {
320
+ #[ allow( non_snake_case , unused_attributes) ]
321
+ mod #module {
325
322
extern crate bytes as _bytes;
326
323
extern crate prost as _prost;
327
324
0 commit comments