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