@@ -12,6 +12,7 @@ pub(crate) struct ClassMethodExport {
12
12
pub ( crate ) struct ExportMethod {
13
13
pub ( crate ) sig : Signature ,
14
14
pub ( crate ) args : ExportArgs ,
15
+ pub ( crate ) rpc : String ,
15
16
}
16
17
17
18
#[ derive( Clone , Eq , PartialEq , Ord , PartialOrd , Hash , Debug , Default ) ]
@@ -33,7 +34,7 @@ pub(crate) fn derive_methods(meta: TokenStream, input: TokenStream) -> TokenStre
33
34
let methods = export
34
35
. methods
35
36
. into_iter ( )
36
- . map ( |ExportMethod { sig, args } | {
37
+ . map ( |ExportMethod { sig, args, rpc } | {
37
38
let sig_span = sig. ident . span ( ) ;
38
39
39
40
let name = sig. ident ;
@@ -85,7 +86,7 @@ pub(crate) fn derive_methods(meta: TokenStream, input: TokenStream) -> TokenStre
85
86
fn #name ( #( #args ) * ) -> #ret_ty
86
87
) ;
87
88
88
- #builder. add_method( #name_string, method) ;
89
+ #builder. add_method( #name_string, method, #rpc ) ;
89
90
}
90
91
)
91
92
} )
@@ -153,6 +154,7 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
153
154
let items = match func {
154
155
ImplItem :: Method ( mut method) => {
155
156
let mut export_args = None ;
157
+ let mut rpc = "disabled" ;
156
158
157
159
let mut errors = vec ! [ ] ;
158
160
@@ -218,7 +220,12 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
218
220
}
219
221
} ;
220
222
221
- for MetaNameValue { path, .. } in pairs {
223
+ for MetaNameValue {
224
+ path,
225
+ eq_token : _,
226
+ lit,
227
+ } in pairs
228
+ {
222
229
let last = match path. segments . last ( ) {
223
230
Some ( val) => val,
224
231
None => {
@@ -229,9 +236,58 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
229
236
return false ;
230
237
}
231
238
} ;
232
- let unexpected = last. ident . to_string ( ) ;
233
- let msg =
234
- format ! ( "unknown option for export: `{}`" , unexpected) ;
239
+ let path = last. ident . to_string ( ) ;
240
+
241
+ // Match rpc mode
242
+ match path. as_str ( ) {
243
+ "rpc" => {
244
+ let value = if let syn:: Lit :: Str ( lit_str) = lit {
245
+ lit_str. value ( )
246
+ } else {
247
+ errors. push ( syn:: Error :: new (
248
+ last. span ( ) ,
249
+ "unexpected type for rpc value, expected Str" ,
250
+ ) ) ;
251
+ return false ;
252
+ } ;
253
+
254
+ match value. as_str ( ) {
255
+ "remote" => {
256
+ rpc = "remote" ;
257
+ return false ;
258
+ }
259
+ "remotesync" => {
260
+ rpc = "remotesync" ;
261
+ return false ;
262
+ }
263
+ "master" => {
264
+ rpc = "master" ;
265
+ return false ;
266
+ }
267
+ "puppet" => {
268
+ rpc = "puppet" ;
269
+ return false ;
270
+ }
271
+ "disabled" => {
272
+ rpc = "disabled" ;
273
+ return false ;
274
+ }
275
+ _ => {
276
+ errors. push ( syn:: Error :: new (
277
+ last. span ( ) ,
278
+ format ! (
279
+ "unexpected value for rpc: {}" ,
280
+ value
281
+ ) ,
282
+ ) ) ;
283
+ return false ;
284
+ }
285
+ }
286
+ }
287
+ _ => ( ) ,
288
+ }
289
+
290
+ let msg = format ! ( "unknown option for export: `{}`" , path) ;
235
291
errors. push ( syn:: Error :: new ( last. span ( ) , msg) ) ;
236
292
}
237
293
}
@@ -287,6 +343,7 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
287
343
methods_to_export. push ( ExportMethod {
288
344
sig : method. sig . clone ( ) ,
289
345
args : export_args,
346
+ rpc : rpc. to_string ( ) ,
290
347
} ) ;
291
348
}
292
349
0 commit comments