@@ -9,7 +9,9 @@ use super::*;
9
9
use crate :: builtin:: * ;
10
10
use crate :: global;
11
11
use crate :: meta:: error:: { ConvertError , FromVariantError } ;
12
- use crate :: meta:: { ArrayElement , GodotFfiVariant , GodotType , PropertyHintInfo , PropertyInfo } ;
12
+ use crate :: meta:: {
13
+ ArrayElement , GodotFfiVariant , GodotType , PropertyHintInfo , PropertyInfo , RefArg ,
14
+ } ;
13
15
use godot_ffi as sys;
14
16
// For godot-cpp, see https://github.com/godotengine/godot-cpp/blob/master/include/godot_cpp/core/type_info.hpp.
15
17
@@ -22,7 +24,15 @@ use godot_ffi as sys;
22
24
//
23
25
// Therefore, we can use `init` to indicate when it must be initialized in 4.0.
24
26
macro_rules! impl_ffi_variant {
25
- ( $T: ty, $from_fn: ident, $to_fn: ident $( ; $godot_type_name: ident) ?) => {
27
+ ( ref $T: ty, $from_fn: ident, $to_fn: ident $( ; $GodotTy: ident) ?) => {
28
+ impl_ffi_variant!( @impls by_ref; $T, $from_fn, $to_fn $( ; $GodotTy) ?) ;
29
+ } ;
30
+ ( $T: ty, $from_fn: ident, $to_fn: ident $( ; $GodotTy: ident) ?) => {
31
+ impl_ffi_variant!( @impls by_val; $T, $from_fn, $to_fn $( ; $GodotTy) ?) ;
32
+ } ;
33
+
34
+ // Implementations
35
+ ( @impls $by_ref_or_val: ident; $T: ty, $from_fn: ident, $to_fn: ident $( ; $GodotTy: ident) ?) => {
26
36
impl GodotFfiVariant for $T {
27
37
fn ffi_to_variant( & self ) -> Variant {
28
38
let variant = unsafe {
@@ -58,10 +68,7 @@ macro_rules! impl_ffi_variant {
58
68
59
69
impl GodotType for $T {
60
70
type Ffi = Self ;
61
-
62
- fn to_ffi( & self ) -> Self :: Ffi {
63
- self . clone( )
64
- }
71
+ impl_ffi_variant!( @assoc_to_ffi $by_ref_or_val) ;
65
72
66
73
fn into_ffi( self ) -> Self :: Ffi {
67
74
self
@@ -71,7 +78,7 @@ macro_rules! impl_ffi_variant {
71
78
Ok ( ffi)
72
79
}
73
80
74
- impl_ffi_variant!( @godot_type_name $T $( , $godot_type_name ) ?) ;
81
+ impl_ffi_variant!( @godot_type_name $T $( , $GodotTy ) ?) ;
75
82
}
76
83
77
84
impl ArrayElement for $T { }
@@ -88,6 +95,22 @@ macro_rules! impl_ffi_variant {
88
95
stringify!( $godot_type_name) . into( )
89
96
}
90
97
} ;
98
+
99
+ ( @assoc_to_ffi by_ref) => {
100
+ type ToFfi <' a> = RefArg <' a, Self >;
101
+
102
+ fn to_ffi( & self ) -> Self :: ToFfi <' _> {
103
+ RefArg :: new( self )
104
+ }
105
+ } ;
106
+
107
+ ( @assoc_to_ffi by_val) => {
108
+ type ToFfi <' a> = Self ;
109
+
110
+ fn to_ffi( & self ) -> Self :: ToFfi <' _> {
111
+ self . clone( )
112
+ }
113
+ } ;
91
114
}
92
115
93
116
// ----------------------------------------------------------------------------------------------------------------------------------------------
@@ -116,17 +139,17 @@ mod impls {
116
139
impl_ffi_variant ! ( GString , string_to_variant, string_from_variant; String ) ;
117
140
impl_ffi_variant ! ( StringName , string_name_to_variant, string_name_from_variant) ;
118
141
impl_ffi_variant ! ( NodePath , node_path_to_variant, node_path_from_variant) ;
119
- impl_ffi_variant ! ( PackedByteArray , packed_byte_array_to_variant, packed_byte_array_from_variant) ;
120
- impl_ffi_variant ! ( PackedInt32Array , packed_int32_array_to_variant, packed_int32_array_from_variant) ;
121
- impl_ffi_variant ! ( PackedInt64Array , packed_int64_array_to_variant, packed_int64_array_from_variant) ;
122
- impl_ffi_variant ! ( PackedFloat32Array , packed_float32_array_to_variant, packed_float32_array_from_variant) ;
123
- impl_ffi_variant ! ( PackedFloat64Array , packed_float64_array_to_variant, packed_float64_array_from_variant) ;
124
- impl_ffi_variant ! ( PackedStringArray , packed_string_array_to_variant, packed_string_array_from_variant) ;
125
- impl_ffi_variant ! ( PackedVector2Array , packed_vector2_array_to_variant, packed_vector2_array_from_variant) ;
126
- impl_ffi_variant ! ( PackedVector3Array , packed_vector3_array_to_variant, packed_vector3_array_from_variant) ;
142
+ impl_ffi_variant ! ( ref PackedByteArray , packed_byte_array_to_variant, packed_byte_array_from_variant) ;
143
+ impl_ffi_variant ! ( ref PackedInt32Array , packed_int32_array_to_variant, packed_int32_array_from_variant) ;
144
+ impl_ffi_variant ! ( ref PackedInt64Array , packed_int64_array_to_variant, packed_int64_array_from_variant) ;
145
+ impl_ffi_variant ! ( ref PackedFloat32Array , packed_float32_array_to_variant, packed_float32_array_from_variant) ;
146
+ impl_ffi_variant ! ( ref PackedFloat64Array , packed_float64_array_to_variant, packed_float64_array_from_variant) ;
147
+ impl_ffi_variant ! ( ref PackedStringArray , packed_string_array_to_variant, packed_string_array_from_variant) ;
148
+ impl_ffi_variant ! ( ref PackedVector2Array , packed_vector2_array_to_variant, packed_vector2_array_from_variant) ;
149
+ impl_ffi_variant ! ( ref PackedVector3Array , packed_vector3_array_to_variant, packed_vector3_array_from_variant) ;
127
150
#[ cfg( since_api = "4.3" ) ]
128
- impl_ffi_variant ! ( PackedVector4Array , packed_vector4_array_to_variant, packed_vector4_array_from_variant) ;
129
- impl_ffi_variant ! ( PackedColorArray , packed_color_array_to_variant, packed_color_array_from_variant) ;
151
+ impl_ffi_variant ! ( ref PackedVector4Array , packed_vector4_array_to_variant, packed_vector4_array_from_variant) ;
152
+ impl_ffi_variant ! ( ref PackedColorArray , packed_color_array_to_variant, packed_color_array_from_variant) ;
130
153
impl_ffi_variant ! ( Plane , plane_to_variant, plane_from_variant) ;
131
154
impl_ffi_variant ! ( Projection , projection_to_variant, projection_from_variant) ;
132
155
impl_ffi_variant ! ( Rid , rid_to_variant, rid_from_variant; RID ) ;
@@ -135,7 +158,7 @@ mod impls {
135
158
impl_ffi_variant ! ( Signal , signal_to_variant, signal_from_variant) ;
136
159
impl_ffi_variant ! ( Transform2D , transform_2d_to_variant, transform_2d_from_variant) ;
137
160
impl_ffi_variant ! ( Transform3D , transform_3d_to_variant, transform_3d_from_variant) ;
138
- impl_ffi_variant ! ( Dictionary , dictionary_to_variant, dictionary_from_variant) ;
161
+ impl_ffi_variant ! ( ref Dictionary , dictionary_to_variant, dictionary_from_variant) ;
139
162
140
163
}
141
164
@@ -162,9 +185,10 @@ impl GodotFfiVariant for () {
162
185
}
163
186
164
187
impl GodotType for ( ) {
165
- type Ffi = Self ;
188
+ type Ffi = ( ) ;
189
+ type ToFfi < ' a > = ( ) ;
166
190
167
- fn to_ffi ( & self ) -> Self :: Ffi { }
191
+ fn to_ffi ( & self ) -> Self :: ToFfi < ' _ > { }
168
192
169
193
fn into_ffi ( self ) -> Self :: Ffi { }
170
194
@@ -189,9 +213,10 @@ impl GodotFfiVariant for Variant {
189
213
190
214
impl GodotType for Variant {
191
215
type Ffi = Variant ;
216
+ type ToFfi < ' a > = RefArg < ' a , Variant > ;
192
217
193
- fn to_ffi ( & self ) -> Self :: Ffi {
194
- self . clone ( )
218
+ fn to_ffi ( & self ) -> Self :: ToFfi < ' _ > {
219
+ RefArg :: new ( self )
195
220
}
196
221
197
222
fn into_ffi ( self ) -> Self :: Ffi {
0 commit comments