1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
//! # Internal crate of [**godot-rust**](https://godot-rust.github.io)
//!
//! Do not depend on this crate directly, instead use the `godot` crate.
//! No SemVer or other guarantees are provided.
use TokenStream;
use TokenStream as TokenStream2;
use crate;
// Below intra-doc link to the trait only works as HTML, not as symbol link.
/// Derive macro for [`GodotClass`](../obj/trait.GodotClass.html) on structs.
///
/// You should use this macro; manual implementations of the `GodotClass` trait are not encouraged.
///
/// This is typically used in combination with [`#[godot_api]`](attr.godot_api.html), which can implement custom functions and constants,
/// as well as override virtual methods.
///
/// See also [book chapter _Registering classes_](https://godot-rust.github.io/book/register/classes.html).
///
/// **See sidebar on the left for table of contents.**
///
///
/// # Construction
///
/// If you don't override `init()` manually (within a `#[godot_api]` block), gdext can generate a default constructor for you.
/// This constructor is made available to Godot and lets you call `MyStruct.new()` from GDScript. To enable it, annotate your
/// struct with `#[class(init)]`:
///
/// ```no_run
/// # use godot_macros::GodotClass;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// // ...
/// }
/// ```
///
/// The generated `init` function will initialize each struct field (except the field of type `Base<T>`, if any)
/// using `Default::default()`. To assign some other value, annotate the field with `#[init(val = ...)]`:
///
/// ```no_run
/// # use godot_macros::GodotClass;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// #[init(val = 42)]
/// my_field: i64
/// }
/// ```
///
/// The given value can be any Rust expression that can be evaluated in the scope where you write
/// the attribute. However, due to limitations in the parser, some complex expressions must be
/// surrounded by parentheses. This is the case if the expression includes a `,` that is _not_
/// inside any pair of `(...)`, `[...]` or `{...}` (even if it is, for example, inside `<...>` or
/// `|...|`). A contrived example:
///
/// ```no_run
/// # use godot_macros::GodotClass;
/// # use std::collections::HashMap;
/// # #[derive(GodotClass)]
/// # #[class(init)]
/// # struct MyStruct {
/// #[init(val = (HashMap::<i64, i64>::new()))]
/// // ^ parentheses needed due to this comma
/// my_field: HashMap<i64, i64>,
/// # }
/// ```
///
/// You can also _disable_ construction from GDScript. This needs to be explicit via `#[class(no_init)]`.
/// Simply omitting the `init`/`no_init` keys and not overriding your own constructor will cause a compile error.
///
/// ```no_run
/// # use godot_macros::GodotClass;
/// #[derive(GodotClass)]
/// #[class(no_init)]
/// struct MyStruct {
/// // ...
/// }
/// ```
///
/// # Inheritance
///
/// Unlike C++, Rust doesn't really have inheritance, but the GDExtension API lets us "inherit"
/// from a Godot-provided engine class.
///
/// By default, non-singleton classes created with this library inherit from `RefCounted`, like GDScript.
///
/// To specify a different class to inherit from, add `#[class(base = Base)]` as an annotation on
/// your `struct`:
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node2D)]
/// struct MyStruct {
/// // ...
/// }
/// ```
///
/// If you need a reference to the base class, you can add a field of type `Base<T>`. The derive macro will pick this up and wire
/// your object accordingly. You can access it through `self.base()` and `self.base_mut()` methods.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node2D)]
/// struct MyStruct {
/// base: Base<Node2D>,
/// }
/// ```
///
///
/// # Properties and exports
///
/// See also [book chapter _Registering properties_](https://godot-rust.github.io/book/register/properties.html#registering-properties).
///
/// In GDScript, there is a distinction between
/// [properties](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#properties-setters-and-getters)
/// (fields with a `get` or `set` declaration) and
/// [exports](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html)
/// (fields annotated with `@export`). In the gdext API, these two concepts are represented with `#[var]` and `#[export]` attributes respectively,
/// which in turn are backed by the [`Var`](../register/property/trait.Var.html) and [`Export`](../register/property/trait.Export.html) traits.
///
/// ## Register properties -- `#[var]`
///
/// To create a property, you can use the `#[var]` annotation, which supports types implementing [`Var`](../register/property/trait.Var.html).
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// #[var]
/// my_field: i64,
/// }
/// ```
///
/// This makes the field accessible in GDScript using `obj.my_field` syntax. In addition to direct property access, GDScript can use
/// explicit getter and setter notation: `obj.get_my_field()` and `obj.set_my_field()`.
///
/// If you want to access those getters/setters from Rust, you can use `#[var(pub)]`:
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// #[var(pub)]
/// my_field: i64,
/// }
///
/// fn use_accessors(obj: &MyStruct) {
/// let f: i64 = obj.get_my_field();
/// }
/// ```
///
/// You can also customize getters and setters.
/// The `get` and `set` options are **orthogonal** as of godot-rust v0.5: specifying one does not affect the other.
/// By default, both a getter and setter are generated, but you can customize either independently:
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// // Auto-generated getter and setter.
/// #[var]
/// a: i64,
///
/// // Looks for setter `set_b` defined by user. Name is derived from field name.
/// #[var(set)]
/// b: i64,
///
/// // Looks for custom-named setter `my_set_c` defined by user.
/// #[var(set = my_set_c)]
/// c: i64,
///
/// // No setter, default getter (read-only).
/// #[var(no_set)]
/// d: i64,
///
/// // Same principle for getters.
/// }
///
/// #[godot_api]
/// impl MyStruct {
/// #[func] // #[func] is needed to make function visible to Godot.
/// pub fn set_b(&mut self, value: i64) {
/// if value % 3 == 0 { // Example: perform validation.
/// self.b = value;
/// }
/// }
///
/// #[func]
/// pub fn my_set_c(&mut self, value: i64) {
/// self.c = value.max(0); // Example: clamp to non-negative.
/// }
/// }
/// ```
///
/// If you want the field to have a different name in Godot and Rust, you can use `rename`:
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// #[var(rename = my_godot_field)]
/// my_rust_field: i64,
/// }
/// ```
///
/// With this, you can access this field as `my_rust_field` in Rust code, however when accessing it from Godot you have to
/// use `my_godot_field` instead (including when using methods such as [`Object::get`](../classes/struct.Object.html#method.get)).
/// The generated getters and setters will also be named `get/set_my_godot_field`, instead of `get/set_my_rust_field`.
///
/// To create a property without a backing field to store data, you can use [`PhantomVar`](../prelude/struct.PhantomVar.html).
/// This disables autogenerated getters and setters for that field.
///
/// ## Export properties -- `#[export]`
///
/// To export properties to the editor, you can use the `#[export]` attribute, which supports types implementing
/// [`Export`](../register/property/trait.Export.html):
///
/// ```no_run
/// # use godot::prelude::{GodotClass, Node3D, Gd, OnEditor};
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// #[export]
/// my_field: i64,
///
/// #[export]
/// child: OnEditor<Gd<Node3D>>,
/// }
/// ```
///
/// If you don't include an additional `#[var]` attribute, then a default one will be generated.
///
/// `#[export]` also supports all of [GDScript's annotations][gdscript-annotations], in a slightly different format. The format is
/// translated from an annotation by following these four rules:
///
/// [gdscript-annotations]: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html
///
/// | GDScript annotation | Rust attribute |
/// |---------------------------------------------|-------------------------------------------------|
/// | `@export` | `#[export]` |
/// | `@export_key` | `#[export(key)]` |
/// | `@export_key(elem1, ...)` | `#[export(key = (elem1, ...))]` |
/// | `@export_flags("elem1", "elem2:val2", ...)`<br>`@export_enum("elem1", "elem2:val2", ...)` | `#[export(flags = (elem1, elem2 = val2, ...))]`<br>`#[export(enum = (elem1, elem2 = val2, ...))]` |
///
/// As an example of different export attributes:
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// // @export
/// #[export]
/// float: f64,
///
/// // @export_storage
/// #[export(storage)]
/// hidden_string: GString,
///
/// // @export_range(0.0, 10.0, or_greater)
/// #[export(range = (0.0, 10.0, or_greater))]
/// range_f64: f64,
///
/// // @export_file
/// #[export(file)]
/// file: GString,
///
/// // @export_file("*.gd")
/// #[export(file = "*.gd")]
/// gdscript_file: GString,
///
/// // @export_flags_3d_physics
/// #[export(flags_3d_physics)]
/// physics: u32,
///
/// // @export_exp_easing
/// #[export(exp_easing)]
/// ease: f64,
///
/// // @export_enum("One", "Two", "Ten:10", "Twelve:12", "Thirteen")
/// #[export(enum = (One, Two, Ten = 10, Twelve = 12, Thirteen))]
/// exported_enum: i64,
///
/// // @export_flags("A:1", "B:2", "AB:3")
/// #[export(flags = (A = 1, B = 2, AB = 3))]
/// flags: u32,
/// }
///
/// ```
///
/// Most values in syntax such as `key = value` can be arbitrary expressions. For example, you can use constants, function calls or
/// other Rust expressions that are valid in that context.
///
/// ```no_run
/// # use godot::prelude::*;
/// const MAX_HEALTH: f64 = 100.0;
///
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// #[export(range = (0.0, MAX_HEALTH))]
/// health: f64,
///
/// #[export(flags = (A = 0b0001, B = 0b0010, C = 0b0100, D = 0b1000))]
/// flags: u32,
/// }
/// ```
///
/// It is possible to group your exported properties inside the Inspector with the `#[export_group(name = "...", prefix = "...")]` attribute.
/// Every exported property after this attribute will be added to the group. Start a new group or use `#[export_group(name = "")]` (with an empty name) to break out.
///
/// Groups cannot be nested but subgroups can be declared with an `#[export_subgroup]` attribute.
///
/// GDExtension groups and subgroups follow the same rules as the gdscript ones.
///
/// <div class="warning">
/// Nesting subgroups with the slash separator `/` <strong>outside</strong> the group is not supported and might crash the editor.
/// </div>
///
/// See also in Godot docs:
/// [Grouping Exports](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html#grouping-exports)
///
///```no_run
/// # use godot::prelude::*;
/// const MAX_HEALTH: f64 = 100.0;
///
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// // @export_group("Group 1")
/// // @export var group_1_field: int
/// #[export]
/// #[export_group(name = "Group 1")]
/// group_1_field: i32,
///
/// // @export var group_1_field2: int
/// #[export]
/// group_1_field2: i32,
///
/// // @export_group("my group", "grouped_")
/// // @export var grouped_field: int
/// #[export_group(name = "my group", prefix = "grouped_")]
/// #[export]
/// grouped_field: u32,
///
/// // @export_subgroup("my subgroup")
/// // @export var sub_field: int
/// #[export_subgroup(name = "my subgroup")]
/// #[export]
/// sub_field: u32,
///
/// // Breaks out of subgroup `"my subgroup"`.
/// // @export_subgroup("")
/// // @export var grouped_field2: int
/// #[export_subgroup(name = "")]
/// #[export]
/// grouped_field2: u32,
///
/// // @export var ungrouped_field: int
/// #[export]
/// ungrouped_field: i64,
/// }
///```
///
///
/// ## Low-level property hints and usage
///
/// You can specify custom property hints, hint strings, and usage flags in a `#[var]` attribute using the `hint`, `hint_string`
/// and `usage_flags` keys in the attribute. Hint and usage flags are constants in the [`PropertyHint`] and [`PropertyUsageFlags`] enums,
/// while hint strings are dependent on the hint, property type and context. Using these low-level keys is rarely necessary, as most common
/// combinations are covered by `#[var]` and `#[export]` already.
///
/// [`PropertyHint`]: ../register/info/struct.PropertyHint.html
/// [`PropertyUsageFlags`]: ../register/info/struct.PropertyUsageFlags.html
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// # #[class(init)]
/// struct MyStruct {
/// // Treated as an enum with two values: "One" and "Two",
/// // displayed in the editor,
/// // treated as read-only by the editor.
/// #[var(
/// hint = ENUM,
/// hint_string = "One,Two",
/// usage_flags = [EDITOR, READ_ONLY]
/// )]
/// my_field: i64,
/// }
/// ```
///
///
/// # Further class customization
///
/// ## Running code in the editor (tool)
///
/// If you annotate a class with `#[class(tool)]`, its lifecycle methods (`ready()`, `process()` etc.) will be invoked in the editor. This
/// is useful for writing custom editor plugins, as opposed to classes running simply in-game.
///
/// See [`ExtensionLibrary::editor_run_behavior()`](../init/trait.ExtensionLibrary.html#method.editor_run_behavior)
/// for more information and further customization.
///
/// This behaves similarly to [GDScript's `@tool` feature](https://docs.godotengine.org/en/stable/tutorials/plugins/running_code_in_the_editor.html).
///
/// **Note**: As in GDScript, the class must be marked as a `tool` to be accessible in the editor (e.g., for use by editor plugins and inspectors).
///
/// ## Export tool button
///
/// If you need a clickable inspector button on a tool class, use [`PhantomVar<Callable>`](../register/property/struct.PhantomVar.html) with
/// the `#[export_tool_button]` attribute. This exports a `Callable` property as a clickable button. When the button is pressed, the callable
/// is invoked.
///
/// The `#[export_tool_button]` attribute accepts the following arguments:
/// - **`fn`** (required): a Rust expression that evaluates to a function. This can be a path to a method (`Self::my_method`) or global function
/// (`my_function`). The expression receives a `&mut Self` reference when the button is clicked.
/// - **`name`** (optional): a string literal used as the button label in the inspector. If not provided, it is derived from the field name, with
/// underscores replaced by spaces.
/// - **`icon`** (optional): a string literal naming an editor icon to display on the button. Must match one of the icon file names from the
/// [editor/icons] folder of the Godot source repository, without the `.svg` extension (case-sensitive, e.g. `"Node2D"` for `Node2D.svg`).
/// You can browse available icons on the [Godot editor icons website]. Only built-in editor icons can be used; custom icons from the project
/// folder are not supported.
///
/// ```no_run
/// use godot::prelude::*;
/// use godot::obj::WithBaseField;
///
/// #[derive(GodotClass)]
/// #[class(init, tool, base = Node)]
/// struct MyStruct {
/// #[export_tool_button(fn = Self::my_method, icon = "2DNodes")]
/// tool_button: PhantomVar<Callable>,
///
/// #[export_tool_button(fn = generic_fn, name = "My custom name for tool button")]
/// my_other_tool_button: PhantomVar<Callable>,
///
/// base: Base<Node>,
/// }
///
/// #[godot_api]
/// impl MyStruct {
/// fn my_method(&mut self) { /* ... */ }
/// }
///
/// fn generic_fn<T: GodotClass<Base=Node> + WithBaseField>(this: &mut T) {
/// let mut node = Node::new_alloc();
/// this.base_mut().add_child(&node);
/// }
/// ```
///
/// A class with `#[export_tool_button]` fields must have `#[class(tool)]` and a `Base<T>` field. \
/// `#[export_tool_button]` cannot be combined with `#[var]` or `#[export]` on the same field. \
/// The following examples will fail to compile:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// // Not a tool.
/// #[class(init, base = Node)]
/// struct MyStruct {
/// #[export_tool_button(fn = Self::my_method)]
/// tool_button: PhantomVar<Callable>,
/// base: Base<Node>
/// }
/// ```
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base = Node)]
/// struct MyStruct {
/// #[export_tool_button(fn = Self::my_method)]
/// tool_button: PhantomVar<Callable>,
/// // Base field is absent.
/// }
/// ```
///
/// Callables generated by `#[export_tool_button]` become invalid after hot reload; keeping references to them is unsound
/// and will crash the editor.
///
/// `#[export_tool_button(fn = ...)]` is a shortcut for `#[var(...)]` that automatically generates a getter returning a
/// Callable that executes the specified function. The following section provides such an example.
///
/// <details>
/// <summary><i>Expand...</i></summary>
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(tool, init, base=Node)]
/// struct Caller {
/// // This declaration...
/// #[var(
/// no_set,
/// get = get_my_callable,
/// usage_flags = [EDITOR],
/// hint = TOOL_BUTTON,
/// hint_string = "My tool button!,2DNodes"
/// )]
/// my_first_tool_button: PhantomVar<Callable>,
///
/// // ...is equivalent to:
/// #[export_tool_button(
/// fn = Self::my_method,
/// name = "My tool button!",
/// icon = "2DNodes"
/// )]
/// my_second_tool_button: PhantomVar<Callable>,
///
/// // Base is required.
/// base: Base<Node>
/// }
///
/// #[godot_api]
/// impl Caller {
/// #[func]
/// fn get_my_callable(&self) -> Callable {
/// let mut obj = self.to_gd();
/// Callable::from_fn("my tool button callable", move |_args| Self::my_method(&mut *obj.bind_mut()))
/// }
///
/// fn my_method(&mut self) {
/// godot_print!("Hello from my fn!");
/// }
/// }
/// ```
///
/// </details>
///
/// The GDScript equivalent of `#[export_tool_button]` is [`@export_tool_button`]. This feature requires at least Godot 4.4.
///
/// [`@export_tool_button`]: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html#export-tool-button
/// [editor/icons]: https://github.com/godotengine/godot/tree/master/editor/icons
/// [Godot editor icons website]: https://godotengine.github.io/editor-icons
///
/// ## Editor plugins
///
/// Classes inheriting `EditorPlugin` will be automatically instantiated and added
/// to the editor when launched.
///
/// See [Godot's documentation of editor plugins](https://docs.godotengine.org/en/stable/tutorials/plugins/editor/index.html)
/// for more information about editor plugins. But note that you do not need to create and enable the plugin
/// through Godot's `Create New Plugin` menu for it to work, simply creating the class which inherits `EditorPlugin`
/// automatically enables it when the library is loaded.
///
/// This should usually be combined with `#[class(tool)]` so that the code you write will actually run in the
/// editor.
///
/// ### Editor plugins -- hot reload interaction
///
/// During hot reload, Godot firstly unloads `EditorPlugin`s, then changes all alive GDExtension classes instances into their base objects
/// (classes inheriting `Resource` become `Resource`, classes inheriting `Node` become `Node` and so on), then reloads all the classes,
/// and finally changes said instances back into their proper classes.
///
/// `EditorPlugin` will be re-added to the editor before the last step (changing instances from base classes to extension classes) is finished,
/// which might cause issues with loading already cached resources and instantiated nodes.
///
/// In such a case, await one frame until extension is properly hot-reloaded (See: [`godot::task::spawn()`](../task/fn.spawn.html)).
///
/// ## Class renaming
///
/// You may want to have structs with the same name. With Rust, this is allowed using `mod`. However, in GDScript
/// there are no modules, namespaces, or any such disambiguation. Therefore, you need to change the names before they
/// can get to Godot. You can use the `rename` key while defining your `GodotClass` for this.
///
/// ```no_run
/// mod animal {
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, rename=AnimalToad)]
/// pub struct Toad {}
/// }
///
/// mod npc {
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, rename=NpcToad)]
/// pub struct Toad {}
/// }
/// ```
///
/// These classes will appear in the Godot editor and GDScript as "AnimalToad" or "NpcToad".
///
/// ## Class hiding
///
/// If you want to register a class with Godot, but not display in the editor (e.g. when creating a new node), you can use `#[class(internal)]`.
///
/// Classes starting with "Editor" are auto-hidden by Godot. They *must* be marked as internal in godot-rust.
///
/// ```
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(base=Node, init, internal)]
/// pub struct Foo {}
/// ```
///
/// Even though this class is a `Node` and it has an init function, it still won't show up in the editor as a node you can add to a scene
/// because we have added a `hidden` key to the class. This will also prevent it from showing up in documentation.
///
/// ## User-defined Singletons
///
/// Non-refcounted classes can be registered as an engine singleton with `#[class(singleton)]`.
///
/// ```no_run
/// # use godot::prelude::*;
/// # use godot::classes::Object;
/// #[derive(GodotClass)]
/// #[class(init, singleton)]
/// struct MySingleton {
/// my_field: i32,
/// // For `#[class(singleton)]`, the default base is Object, not RefCounted.
/// base: Base<Object>,
/// }
///
/// // Can be accessed like any other engine singleton from the main thread.
/// let val = MySingleton::singleton().bind().my_field;
/// ```
///
/// By default, engine singletons inherit from `Object` and always run in the editor (implied `#[class(tool)]`).
/// During hot reload, user-defined singletons are not being recreated like other tool classes. Instead, they are freed while unloading the
/// library, and then freshly instantiated after other classes have been registered.
///
/// GDScript will be prohibited from creating new instances of said class.
///
/// User-defined singletons must have an `init` constructor:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(no_init, singleton)]
/// struct MySingleton {
/// my_field: i32,
/// }
/// ```
///
///
/// # Further field customization
///
/// ## Fine-grained inference hints
///
/// The derive macro is relatively smart about recognizing `Base<T>` and `OnReady<T>` types, and works also if those are qualified.
///
/// However, there may be situations where you need to help it out -- for example, if you have a type alias for `Base<T>`, or use an unrelated
/// `my_module::Base<T>` with a different meaning.
///
/// In this case, you can manually override the behavior with the `#[hint]` attribute. It takes multiple standalone keys:
/// - `base` and `no_base`
/// - `onready` and `no_onready`
///
/// ```no_run
/// use godot::classes::Node;
///
/// // There's no reason to do this, but for the sake of example:
/// type Super<T> = godot::obj::Base<T>;
/// type Base<T> = godot::obj::Gd<T>;
///
/// #[derive(godot::register::GodotClass)]
/// #[class(base=Node)]
/// struct MyStruct {
/// #[hint(base)]
/// base: Super<Node>,
///
/// #[hint(no_base)]
/// unbase: Base<Node>,
/// }
/// # #[godot::register::godot_api]
/// # impl godot::classes::INode for MyStruct {
/// # fn init(base: godot::obj::Base<Self::Base>) -> Self { todo!() }
/// # }
/// ```
///
/// # Documentation
///
/// <div class="stab portability">Available on <strong>crate feature <code>register-docs</code></strong> only.</div>
/// <div class="stab portability">Available on <strong>Godot version <code>4.3+</code></strong> only.</div>
///
/// You can document your functions, classes, members, and signals with the `///` doc comment syntax.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// # #[class(init)]
/// /// This is an example struct for documentation, inside documentation.
/// struct DocumentedStruct {
/// /// This is a class member.
/// /// You can use markdown formatting such as _italics_.
/// ///
/// /// @experimental `@experimental` and `@deprecated` attributes are supported.
/// /// The description for such attribute spans for the whole annotated paragraph.
/// ///
/// /// This is the rest of a doc description.
/// #[var]
/// item: f32,
/// }
///
/// #[godot_api]
/// impl DocumentedStruct {
/// /// This provides the item, after adding `0.2`.
/// #[func]
/// pub fn produce_item(&self) -> f32 {
/// self.item + 0.2
/// }
/// }
/// ```
/// Proc-macro attribute to be used with `impl` blocks of [`#[derive(GodotClass)]`][GodotClass] structs.
///
/// Can be used in two ways:
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node)]
/// struct MyClass {}
///
/// // 1) inherent impl block: user-defined, custom API.
/// #[godot_api]
/// impl MyClass { /* ... */ }
///
/// // 2) trait impl block: implement Godot-specific APIs.
/// #[godot_api]
/// impl INode for MyClass { /* ... */ }
/// ```
///
/// The second case works by implementing the corresponding trait `I*` for the base class of your class
/// (for example `IRefCounted` or `INode3D`). Then, you can add functionality such as:
/// * `init` constructors
/// * lifecycle methods like `ready` or `process`
/// * `on_notification` method
/// * `to_string` method
///
/// Neither of the two `#[godot_api]` blocks is required. For small data bundles inheriting `RefCounted`, you may be fine with
/// accessing properties directly from GDScript.
///
/// See also [book chapter _Registering functions_](https://godot-rust.github.io/book/register/functions.html) and following.
///
/// **See sidebar on the left for table of contents.**
///
/// # Constructors
///
/// Note that `init` (the Godot default constructor) can be either provided by overriding it, or generated with a `#[class(init)]` attribute
/// on the struct. Classes without `init` cannot be instantiated from GDScript.
///
/// ## User-defined `init`
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// // no #[class(init)] here, since init() is overridden below.
/// // #[class(base=RefCounted)] is implied if no base is specified.
/// struct MyStruct;
///
/// #[godot_api]
/// impl IRefCounted for MyStruct {
/// fn init(_base: Base<RefCounted>) -> Self {
/// MyStruct
/// }
/// }
/// ```
///
/// ## Generated `init`
///
/// This initializes the `Base<T>` field, and every other field with either `Default::default()` or the value specified in `#[init(val = ...)]`.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node)]
/// pub struct MyNode {
/// base: Base<Node>,
///
/// #[init(val = 42)]
/// some_integer: i64,
/// }
/// ```
///
///
/// # Lifecycle functions
///
/// You can override the lifecycle functions `ready`, `process`, `physics_process` and so on, by implementing the trait corresponding to the
/// base class.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node)]
/// pub struct MyNode;
///
/// #[godot_api]
/// impl INode for MyNode {
/// fn ready(&mut self) {
/// godot_print!("Hello World!");
/// }
/// }
/// ```
///
/// Using _any_ trait other than the one corresponding with the base class will result in compilation failure.
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node3D)]
/// pub struct My3DNode;
///
/// #[godot_api]
/// impl INode for My3DNode {
/// fn ready(&mut self) {
/// godot_print!("Hello World!");
/// }
/// }
/// ```
///
/// # User-defined functions
///
/// You can use the `#[func]` attribute to declare your own functions. These are exposed to Godot and callable from GDScript.
///
/// ## Associated functions and methods
///
/// If `#[func]` functions are called from the engine, they implicitly bind the surrounding `Gd<T>` pointer: `Gd::bind()` in case of `&self`,
/// `Gd::bind_mut()` in case of `&mut self`. To avoid that, use `#[func(gd_self)]`, which requires an explicit first argument of type `Gd<T>`.
///
/// Functions without a receiver become static functions in Godot. They can be called from GDScript using `MyStruct.static_function()`.
/// If they return `Gd<Self>`, they are effectively constructors that allow taking arguments.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// field: i64,
/// base: Base<RefCounted>,
/// }
///
/// #[godot_api]
/// impl MyStruct {
/// #[func]
/// pub fn hello_world(&mut self) {
/// godot_print!("Hello World!")
/// }
///
/// #[func]
/// pub fn static_function(constructor_arg: i64) -> Gd<Self> {
/// Gd::from_init_fn(|base| {
/// MyStruct { field: constructor_arg, base }
/// })
/// }
///
/// #[func(gd_self)]
/// pub fn explicit_receiver(mut this: Gd<Self>, other_arg: bool) {
/// // Only bind Gd pointer if needed.
/// if other_arg {
/// this.bind_mut().field = 55;
/// }
/// }
/// }
/// ```
///
/// ## Default parameters
///
/// Functions can have default parameters using the `#[opt]` attribute. When a caller provides fewer arguments than the function
/// signature defines, the default values are used for the missing parameters.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {}
///
/// #[godot_api]
/// impl MyStruct {
/// #[func]
/// fn greet(&self, #[opt(default = "World")] name: GString) {
/// godot_print!("Hello, {name}!");
/// }
/// }
/// ```
/// ```gdscript
/// // Can be called from GDScript as:
/// obj.greet() # prints "Hello, World!"
/// obj.greet("Rust") # prints "Hello, Rust!"
/// ```
///
/// **Important notes:**
/// - Optional parameters must come at the end of the parameter list.
/// - The expression given in `default = ...` must implement [`AsArg<T>`](../meta/trait.AsArg.html) for the parameter type `T`.
/// - Default expressions are evaluated on each function call (not cached). **This may change**, see
/// [PR #1396](https://github.com/godot-rust/gdext/pull/1396).
///
/// ## Virtual methods
///
/// Functions with the `#[func(virtual)]` attribute are virtual functions, meaning attached scripts can override them.
///
/// ```no_run
/// # #[cfg(since_api = "4.3")]
/// # mod conditional {
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// // Virtual functions require base object.
/// base: Base<RefCounted>,
/// }
///
/// #[godot_api]
/// impl MyStruct {
/// #[func(virtual)]
/// fn language(&self) -> GString {
/// GString::from("Rust")
/// }
/// }
/// # }
/// ```
///
/// In GDScript, your method is available with a `_` prefix, following Godot convention for virtual methods:
/// ```gdscript
/// extends MyStruct
///
/// func _language():
/// return "GDScript"
/// ```
///
/// Now, `obj.language()` from Rust will dynamically dispatch the call.
///
/// Make sure you understand the limitations in the [tutorial](https://godot-rust.github.io/book/register/virtual-functions.html).
///
/// ## RPC attributes
///
/// You can use the `#[rpc]` attribute to let your functions act as remote procedure calls (RPCs) in Godot. This is the Rust equivalent of
/// GDScript's [`@rpc` annotation](https://docs.godotengine.org/en/stable/tutorials/networking/high_level_multiplayer.html#remote-procedure-calls).
/// `#[rpc]` is only supported for classes inheriting `Node`, and they need to declare a `Base<T>` field.
///
/// The syntax follows GDScript'a `@rpc`. You can optionally specify up to four keys; omitted ones use their default value.
/// Here's an overview:
///
/// | Setting | Type | Possible values (first is default) |
/// |---------------|------------------|----------------------------------------------------|
/// | RPC mode | [`RpcMode`] | **`authority`**, `any_peer` |
/// | Sync | `bool` | **`call_remote`**, `call_local` |
/// | Transfer mode | [`TransferMode`] | **`unreliable`**, `unreliable_ordered`, `reliable` |
/// | Channel | `u32` | any |
///
/// You can also use `#[rpc(config = value)]`, with `value` being an expression of type [`RpcConfig`] in scope, for example a `const` or the
/// call to a function. This can be useful to reuse configurations across multiple RPCs.
///
/// `#[rpc]` implies `#[func]`. You can use both attributes together, if you need to configure other `#[func]`-specific keys.
///
/// For example, the following method declarations are all equivalent:
/// ```no_run
/// # // Polyfill without full codegen.
/// # #![allow(non_camel_case_types)]
/// # #[cfg(not(feature = "codegen-full"))]
/// # enum RpcMode { DISABLED, ANY_PEER, AUTHORITY }
/// # #[cfg(not(feature = "codegen-full"))]
/// # enum TransferMode { UNRELIABLE, UNRELIABLE_ORDERED, RELIABLE }
/// # #[cfg(not(feature = "codegen-full"))]
/// # pub struct RpcConfig { pub rpc_mode: RpcMode, pub transfer_mode: TransferMode, pub call_local: bool, pub channel: u32 }
/// # #[cfg(not(feature = "codegen-full"))]
/// # impl Default for RpcConfig { fn default() -> Self { todo!("never called") } }
/// # #[cfg(feature = "codegen-full")]
/// use godot::classes::multiplayer_api::RpcMode;
/// # #[cfg(feature = "codegen-full")]
/// use godot::classes::multiplayer_peer::TransferMode;
/// use godot::prelude::*;
/// # #[cfg(feature = "codegen-full")]
/// use godot::register::RpcConfig;
///
/// # #[derive(GodotClass)]
/// # #[class(no_init, base=Node)]
/// # struct MyStruct {
/// # base: Base<Node>,
/// # }
/// #[godot_api]
/// impl MyStruct {
/// #[rpc(unreliable_ordered, channel = 2)]
/// fn with_defaults(&mut self) {}
///
/// #[rpc(authority, unreliable_ordered, call_remote, channel = 2)]
/// fn explicit(&mut self) {}
///
/// #[rpc(config = MY_RPC_CONFIG)]
/// fn external_config_const(&mut self) {}
///
/// #[rpc(config = my_rpc_provider())]
/// fn external_config_fn(&mut self) {}
/// }
///
/// const MY_RPC_CONFIG: RpcConfig = RpcConfig {
/// rpc_mode: RpcMode::AUTHORITY,
/// transfer_mode: TransferMode::UNRELIABLE_ORDERED,
/// call_local: false,
/// channel: 2,
/// };
///
/// fn my_rpc_provider() -> RpcConfig {
/// RpcConfig {
/// transfer_mode: TransferMode::UNRELIABLE_ORDERED,
/// channel: 2,
/// ..Default::default() // only possible in fn, not in const.
/// }
/// }
/// ```
///
// Note: for some reason, the intra-doc links don't work here, despite dev-dependency on godot.
/// [`RpcMode`]: ../classes/multiplayer_api/struct.RpcMode.html
/// [`TransferMode`]: ../classes/multiplayer_peer/struct.TransferMode.html
/// [`RpcConfig`]: ../register/struct.RpcConfig.html
///
/// # Lifecycle functions with custom receivers
///
/// Functions inside I* interface impls, similarly to user-defined `#[func]`s, can be annotated with `#[func(gd_self)]` to use `Gd<Self>` receiver and
/// avoid binding the instance.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node)]
/// pub struct MyNode;
///
/// #[godot_api]
/// impl INode for MyNode {
/// #[func(gd_self)]
/// fn ready(this: Gd<Self>) {
/// godot_print!("I'm ready!");
/// }
/// }
/// ```
///
/// Only methods with `self` receiver can be used with `#[func(gd_self)]`:
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node)]
/// pub struct MyNode;
///
/// #[godot_api]
/// impl INode for MyNode {
/// #[func(gd_self)]
/// fn init(this: Gd<Self>) -> Self {
/// todo!()
/// }
/// }
/// ```
///
/// Currently, `on_notification` can't be used with `[func(gd_self)]`, either:
///
/// ```compile_fail
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init, base=Node)]
/// pub struct MyNode;
///
/// #[godot_api]
/// impl INode for MyNode {
/// #[func(gd_self)]
/// fn on_notification(this: Gd<Self>, what: ObjectNotification) {
/// todo!()
/// }
/// }
/// ```
///
/// # Signals
///
/// The `#[signal]` attribute declares a Godot signal, which can accept parameters, but not return any value.
/// The procedural macro generates a type-safe API that allows you to connect and emit the signal from Rust.
///
/// ```no_run
/// # use godot::prelude::*;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyClass {
/// base: Base<RefCounted>, // Base<...> necessary for #[signal].
/// }
///
/// #[godot_api]
/// impl MyClass {
/// #[signal]
/// fn some_signal(my_parameter: Gd<Node>);
/// }
/// ```
///
/// The above implements the [`WithSignals`] trait for `MyClass`, which provides the `signals()` method. Through that
/// method, you can access all declared signals in `self.signals().some_signal()` or `gd.signals().some_signal()`. The returned object is
/// of type [`TypedSignal`], which provides further APIs for emitting and connecting, among others.
///
/// A detailed explanation with examples is available in the [book chapter _Registering signals_](https://godot-rust.github.io/book/register/signals.html).
///
/// ## Internal signals
///
/// To hide a signal from the Godot editor (docs, autocomplete, signal connection dialog), use `#[signal(internal)]`.
/// The signal is then registered under a `_`-prefixed name in Godot, while the Rust API still uses the original name.
///
/// ```no_run
/// # use godot::prelude::*;
/// # #[derive(GodotClass)]
/// # #[class(init)]
/// # struct MyClass {
/// # base: Base<RefCounted>,
/// # }
/// #[godot_api]
/// impl MyClass {
/// #[signal(internal)]
/// fn hidden_signal(value: i64);
///
/// #[func]
/// fn usage_example(&mut self) {
/// self.signals().hidden_signal().emit(123);
///
/// // Untyped API uses Godot name, with `_` prefix:
/// self.base_mut().emit_signal("_hidden_signal", vslice![123]);
/// }
/// }
/// ```
///
/// This is consistent with `#[class(internal)]` for hiding classes.
///
/// [`WithSignals`]: ../obj/trait.WithSignals.html
/// [`TypedSignal`]: ../register/struct.TypedSignal.html
///
/// # Constants
///
/// Please refer to [the book](https://godot-rust.github.io/book/register/constants.html).
///
/// # Multiple inherent `impl` blocks
///
/// Just like with regular structs, you can have multiple inherent `impl` blocks. This can be useful for code organization or when you want to generate code from a proc-macro.
/// For implementation reasons, all but one `impl` blocks must have the key `secondary`. There is no difference between implementing all functions in one block or splitting them up between multiple blocks.
/// ```no_run
/// # use godot::prelude::*;
/// # #[derive(GodotClass)]
/// # #[class(init)]
/// # struct MyStruct {
/// # base: Base<RefCounted>,
/// # }
/// #[godot_api]
/// impl MyStruct {
/// #[func]
/// pub fn one(&self) { }
/// }
///
/// #[godot_api(secondary)]
/// impl MyStruct {
/// #[func]
/// pub fn two(&self) { }
/// }
/// ```
///
/// `#[signal]` and `#[rpc]` attributes are not currently supported in secondary `impl` blocks.
/// Additionally, `#[var(get = ..., set = ...)]` on fields cannot reference `#[func]` methods defined in secondary blocks.
///
///```compile_fail
/// # use godot::prelude::*;
/// # #[derive(GodotClass)]
/// # #[class(init, base=Node)]
/// # pub struct MyNode { base: Base<Node> }
/// # // Without primary `impl` block the compilation will always fail (no matter if #[signal] attribute is present or not)
/// # #[godot_api]
/// # impl MyNode {}
/// #[godot_api(secondary)]
/// impl MyNode {
/// #[signal]
/// fn my_signal();
/// }
/// ```
///
///```compile_fail
/// # use godot::prelude::*;
/// # #[derive(GodotClass)]
/// # #[class(init, base=Node)]
/// # pub struct MyNode { base: Base<Node> }
/// # // Without primary `impl` block the compilation will always fail (no matter if #[rpc] attribute is present or not).
/// # #[godot_api]
/// # impl MyNode {}
/// #[godot_api(secondary)]
/// impl MyNode {
/// #[rpc]
/// fn foo(&mut self) {}
/// }
/// ```
/// Generates a `Class` -> `dyn Trait` upcasting relation.
///
/// This attribute macro can be applied to `impl MyTrait for MyClass` blocks, where `MyClass` is a `GodotClass`. It will automatically
/// implement [`MyClass: AsDyn<dyn MyTrait>`](../obj/trait.AsDyn.html) for you.
///
/// Establishing this relation allows godot-rust to upcast `MyGodotClass` to `dyn Trait` inside the library's
/// [`DynGd`](../obj/struct.DynGd.html) smart pointer.
///
/// # Code generation
/// Given the following code,
/// ```no_run
/// use godot::prelude::*;
///
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyClass {}
///
/// trait MyTrait {}
///
/// #[godot_dyn]
/// impl MyTrait for MyClass {}
/// ```
/// the macro expands to:
/// ```no_run
/// # use godot::prelude::*;
/// # #[derive(GodotClass)]
/// # #[class(init)]
/// # struct MyClass {}
/// # trait MyTrait {}
/// // impl block remains unchanged...
/// impl MyTrait for MyClass {}
///
/// // ...but a new `impl AsDyn` is added.
/// impl AsDyn<dyn MyTrait> for MyClass {
/// fn dyn_upcast(&self) -> &(dyn MyTrait + 'static) { self }
/// fn dyn_upcast_mut(&mut self) -> &mut (dyn MyTrait + 'static) { self }
/// }
/// ```
///
/// # Orphan rule limitations
/// Since `AsDyn` is always a foreign trait, the `#[godot_dyn]` attribute must be used in the same crate as the Godot class's definition.
/// (Currently, Godot classes cannot be shared from libraries, but this may [change in the future](https://github.com/godot-rust/gdext/issues/951).)
/// Derive macro for [`GodotConvert`](../meta/trait.GodotConvert.html) on structs.
///
/// This derive macro also derives [`ToGodot`](../meta/trait.ToGodot.html) and [`FromGodot`](../meta/trait.FromGodot.html).
///
/// # Choosing a Via type
///
/// To specify the `Via` type that your type should be converted to, you must use the `godot` attribute.
/// There are currently two modes supported.
///
/// ## `transparent`
///
/// If you specify `#[godot(transparent)]` on single-field struct, your struct will be treated as a newtype struct. This means that all derived
/// operations on the struct will defer to the type of that single field.
///
/// ### Example
///
/// ```no_run
/// use godot::prelude::*;
///
/// #[derive(GodotConvert)]
/// #[godot(transparent)]
/// struct CustomVector2(Vector2);
///
/// let obj = CustomVector2(Vector2::new(10.0, 25.0));
/// assert_eq!(obj.to_godot(), Vector2::new(10.0, 25.0));
/// ```
///
/// This also works for named structs with a single field:
/// ```no_run
/// use godot::prelude::*;
///
/// #[derive(GodotConvert)]
/// #[godot(transparent)]
/// struct MyNewtype {
/// string: GString,
/// }
///
/// let obj = MyNewtype {
/// string: "hello!".into(),
/// };
///
/// assert_eq!(obj.to_godot(), &GString::from("hello!"));
/// ```
///
/// However, it will not work for structs with more than one field, even if that field is zero sized:
/// ```compile_fail
/// use godot::prelude::*;
///
/// #[derive(GodotConvert)]
/// #[godot(transparent)]
/// struct SomeNewtype {
/// int: i64,
/// zst: (),
/// }
/// ```
///
/// You can also not use `transparent` with enums:
/// ```compile_fail
/// use godot::prelude::*;
///
/// #[derive(GodotConvert)]
/// #[godot(transparent)]
/// enum MyEnum {
/// Int(i64)
/// }
/// ```
///
/// ## `via = <type>`
///
/// For c-style enums, that is enums where all the variants are unit-like, you can use `via = <type>` to convert the enum into that
/// type.
///
/// The types you can use this with currently are:
/// - `GString`
/// - `i8`, `i16`, `i32`, `i64`
/// - `u8`, `u16`, `u32`
///
/// When using one of the integer types, each variant of the enum will be converted into its discriminant.
///
/// ### Examples
///
/// ```no_run
/// use godot::prelude::*;
/// #[derive(GodotConvert)]
/// #[godot(via = GString)]
/// enum MyEnum {
/// A,
/// B,
/// C,
/// }
///
/// assert_eq!(MyEnum::A.to_godot(), GString::from("A"));
/// assert_eq!(MyEnum::B.to_godot(), GString::from("B"));
/// assert_eq!(MyEnum::C.to_godot(), GString::from("C"));
/// ```
///
/// ```no_run
/// use godot::prelude::*;
/// #[derive(GodotConvert)]
/// #[godot(via = i64)]
/// enum MyEnum {
/// A,
/// B,
/// C,
/// }
///
/// assert_eq!(MyEnum::A.to_godot(), 0);
/// assert_eq!(MyEnum::B.to_godot(), 1);
/// assert_eq!(MyEnum::C.to_godot(), 2);
/// ```
///
/// Explicit discriminants are used for integers:
///
/// ```no_run
/// use godot::prelude::*;
/// #[derive(GodotConvert)]
/// #[godot(via = u8)]
/// enum MyEnum {
/// A,
/// B = 10,
/// C,
/// }
///
/// assert_eq!(MyEnum::A.to_godot(), 0);
/// assert_eq!(MyEnum::B.to_godot(), 10);
/// assert_eq!(MyEnum::C.to_godot(), 11);
/// ```
/// Derive macro for [`Var`](../register/property/trait.Var.html) on enums.
///
/// This expects a derived [`GodotConvert`](../meta/trait.GodotConvert.html) implementation, using a manual
/// implementation of `GodotConvert` may lead to incorrect values being displayed in Godot.
/// Derive macro for [`Export`](../register/property/trait.Export.html) on enums.
///
/// See also [`Var`].
/// Similar to `#[test]`, but runs an integration test with Godot.
///
/// Transforms the `fn` into one returning `bool` (success of the test), which must be called explicitly.
/// Similar to `#[test]`, but runs a benchmark with Godot.
///
/// Calls the `fn` many times and gathers statistics from its execution time.
/// Proc-macro attribute to be used in combination with the [`ExtensionLibrary`] trait.
///
/// [`ExtensionLibrary`]: ../init/trait.ExtensionLibrary.html
// ----------------------------------------------------------------------------------------------------------------------------------------------
// Implementation
type ParseResult<T> = ;
/// For `#[derive(...)]` derive macros.
/// For `#[proc_macro_attribute]` procedural macros.
/// For `#[proc_macro]` function-style macros.
/// Returns the index of the key in `keys` (if any) that is present.