@@ -15,6 +15,21 @@ pub enum RpcMode {
15
15
PuppetSync ,
16
16
}
17
17
18
+ impl RpcMode {
19
+ fn parse ( s : & str ) -> Option < Self > {
20
+ match s {
21
+ "remote" => Some ( RpcMode :: Remote ) ,
22
+ "remote_sync" => Some ( RpcMode :: RemoteSync ) ,
23
+ "master" => Some ( RpcMode :: Master ) ,
24
+ "puppet" => Some ( RpcMode :: Puppet ) ,
25
+ "disabled" => Some ( RpcMode :: Disabled ) ,
26
+ "master_sync" => Some ( RpcMode :: MasterSync ) ,
27
+ "puppet_sync" => Some ( RpcMode :: PuppetSync ) ,
28
+ _ => None ,
29
+ }
30
+ }
31
+ }
32
+
18
33
impl Default for RpcMode {
19
34
fn default ( ) -> Self {
20
35
RpcMode :: Disabled
@@ -188,7 +203,7 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
188
203
let items = match func {
189
204
ImplItem :: Method ( mut method) => {
190
205
let mut export_args = None ;
191
- let mut rpc = RpcMode :: Disabled ;
206
+ let mut rpc = None ;
192
207
193
208
let mut errors = vec ! [ ] ;
194
209
@@ -253,12 +268,7 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
253
268
}
254
269
} ;
255
270
256
- for MetaNameValue {
257
- path,
258
- eq_token : _,
259
- lit,
260
- } in pairs
261
- {
271
+ for MetaNameValue { path, lit, .. } in pairs {
262
272
let last = match path. segments . last ( ) {
263
273
Some ( val) => val,
264
274
None => {
@@ -284,46 +294,23 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
284
294
return false ;
285
295
} ;
286
296
287
- match value. as_str ( ) {
288
- "remote" => {
289
- rpc = RpcMode :: Remote ;
290
- return false ;
291
- }
292
- "remote_sync" => {
293
- rpc = RpcMode :: RemoteSync ;
294
- return false ;
295
- }
296
- "master" => {
297
- rpc = RpcMode :: Master ;
298
- return false ;
299
- }
300
- "puppet" => {
301
- rpc = RpcMode :: Puppet ;
302
- return false ;
303
- }
304
- "disabled" => {
305
- rpc = RpcMode :: Disabled ;
306
- return false ;
307
- }
308
- "master_sync" => {
309
- rpc = RpcMode :: MasterSync ;
310
- return false ;
311
- }
312
- "puppet_sync" => {
313
- rpc = RpcMode :: PuppetSync ;
314
- return false ;
315
- }
316
- _ => {
297
+ if let Some ( mode) = RpcMode :: parse ( value. as_str ( ) ) {
298
+ if rpc. replace ( mode) . is_some ( ) {
317
299
errors. push ( syn:: Error :: new (
318
300
last. span ( ) ,
319
- format ! (
320
- "unexpected value for rpc: {}" ,
321
- value
322
- ) ,
301
+ "rpc mode was set more than once" ,
323
302
) ) ;
324
303
return false ;
325
304
}
305
+ } else {
306
+ errors. push ( syn:: Error :: new (
307
+ last. span ( ) ,
308
+ format ! ( "unexpected value for rpc: {}" , value) ,
309
+ ) ) ;
310
+ return false ;
326
311
}
312
+
313
+ return false ;
327
314
}
328
315
_ => ( ) ,
329
316
}
@@ -380,7 +367,7 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
380
367
}
381
368
382
369
export_args. optional_args = optional_args;
383
- export_args. rpc_mode = rpc;
370
+ export_args. rpc_mode = rpc. unwrap_or ( RpcMode :: Disabled ) ;
384
371
385
372
methods_to_export. push ( ExportMethod {
386
373
sig : method. sig . clone ( ) ,
0 commit comments