8
8
use godot_ffi as sys;
9
9
10
10
use crate :: builtin:: { Array , Variant } ;
11
+ use crate :: meta;
11
12
use crate :: meta:: error:: { ConvertError , ErrorKind , FromFfiError , FromVariantError } ;
12
13
use crate :: meta:: {
13
14
ArrayElement , ClassName , FromGodot , GodotConvert , GodotNullableFfi , GodotType ,
@@ -85,47 +86,47 @@ where
85
86
}
86
87
87
88
// Only relevant for object types T.
88
- unsafe fn as_object_arg ( & self ) -> crate :: meta:: ObjectArg {
89
+ unsafe fn as_object_arg ( & self ) -> meta:: ObjectArg {
89
90
match self {
90
91
Some ( inner) => unsafe { inner. as_object_arg ( ) } ,
91
- None => crate :: meta:: ObjectArg :: null ( ) ,
92
+ None => meta:: ObjectArg :: null ( ) ,
92
93
}
93
94
}
94
95
}
95
96
96
- impl < T : GodotConvert > GodotConvert for Option < T >
97
+ impl < T > GodotConvert for Option < T >
97
98
where
99
+ T : GodotConvert ,
98
100
Option < T :: Via > : GodotType ,
99
101
{
100
102
type Via = Option < T :: Via > ;
101
103
}
102
104
103
- impl < T : ToGodot > ToGodot for Option < T >
105
+ impl < T > ToGodot for Option < T >
104
106
where
105
- Option < T :: Via > : GodotType ,
107
+ // Currently limited to holding objects -> needed to establish to_godot() relation T::to_godot() = Option<&T::Via>.
108
+ T : ToGodot < Pass = meta:: ByObject > ,
109
+ // Extra Clone bound for to_godot_owned(); might be extracted in the future.
110
+ T :: Via : Clone ,
111
+ // T::Via must be a Godot nullable type (to support the None case).
106
112
for < ' f > T :: Via : GodotType <
107
113
// Associated types need to be nullable.
108
114
Ffi : GodotNullableFfi ,
109
115
ToFfi < ' f > : GodotNullableFfi ,
110
116
> ,
111
- T :: Via : Clone ,
117
+ // Previously used bound, not needed right now but don't remove: Option< T::Via>: GodotType ,
112
118
{
113
- // Potential optimization: use underlying T::Pass instead of ByValue.
114
- // Problem is that ByRef requires to_godot() -> &Self::Via, which is &Option<T::Via>. We would however need Option<&T::Via>.
115
- // Might need a third ArgPassing impl, or different design.
116
- type Pass = crate :: meta:: ByValue ;
119
+ // Basically ByRef, but allows Option<T> -> Option<&T::Via> conversion.
120
+ type Pass = meta:: ByOption < T :: Via > ;
117
121
118
- fn to_godot ( & self ) -> Option < T :: Via > {
119
- self . as_ref ( ) . map ( T :: to_godot_owned )
122
+ fn to_godot ( & self ) -> Option < & T :: Via > {
123
+ self . as_ref ( ) . map ( T :: to_godot )
120
124
}
121
125
122
- fn to_godot_owned ( & self ) -> Self :: Via
126
+ fn to_godot_owned ( & self ) -> Option < T :: Via >
123
127
where
124
128
Self :: Via : Clone ,
125
129
{
126
- // Default implementation calls underlying T::to_godot().clone(), which may be wrong.
127
- // Some to_godot_owned() calls are specialized/overridden, we need to honor that.
128
-
129
130
self . as_ref ( ) . map ( T :: to_godot_owned)
130
131
}
131
132
@@ -256,7 +257,7 @@ macro_rules! impl_godot_scalar {
256
257
}
257
258
258
259
impl ToGodot for $T {
259
- type Pass = crate :: meta:: ByValue ;
260
+ type Pass = meta:: ByValue ;
260
261
261
262
fn to_godot( & self ) -> Self :: Via {
262
263
* self
@@ -272,10 +273,10 @@ macro_rules! impl_godot_scalar {
272
273
}
273
274
274
275
// `GodotType` for these three is implemented in `godot-core/src/builtin/variant/impls.rs`.
275
- crate :: meta:: impl_godot_as_self!( bool : ByValue ) ;
276
- crate :: meta:: impl_godot_as_self!( i64 : ByValue ) ;
277
- crate :: meta:: impl_godot_as_self!( f64 : ByValue ) ;
278
- crate :: meta:: impl_godot_as_self!( ( ) : ByValue ) ;
276
+ meta:: impl_godot_as_self!( bool : ByValue ) ;
277
+ meta:: impl_godot_as_self!( i64 : ByValue ) ;
278
+ meta:: impl_godot_as_self!( f64 : ByValue ) ;
279
+ meta:: impl_godot_as_self!( ( ) : ByValue ) ;
279
280
280
281
// Also implements ArrayElement.
281
282
impl_godot_scalar ! (
@@ -342,7 +343,7 @@ impl GodotConvert for u64 {
342
343
}
343
344
344
345
impl ToGodot for u64 {
345
- type Pass = crate :: meta:: ByValue ;
346
+ type Pass = meta:: ByValue ;
346
347
347
348
fn to_godot ( & self ) -> Self :: Via {
348
349
* self
@@ -382,7 +383,7 @@ impl<T: ArrayElement> GodotConvert for Vec<T> {
382
383
}
383
384
384
385
impl < T : ArrayElement > ToGodot for Vec < T > {
385
- type Pass = crate :: meta:: ByValue ;
386
+ type Pass = meta:: ByValue ;
386
387
387
388
fn to_godot ( & self ) -> Self :: Via {
388
389
Array :: from ( self . as_slice ( ) )
@@ -400,7 +401,7 @@ impl<T: ArrayElement, const LEN: usize> GodotConvert for [T; LEN] {
400
401
}
401
402
402
403
impl < T : ArrayElement , const LEN : usize > ToGodot for [ T ; LEN ] {
403
- type Pass = crate :: meta:: ByValue ;
404
+ type Pass = meta:: ByValue ;
404
405
405
406
fn to_godot ( & self ) -> Self :: Via {
406
407
Array :: from ( self )
@@ -440,7 +441,7 @@ impl<T: ArrayElement> GodotConvert for &[T] {
440
441
}
441
442
442
443
impl < T : ArrayElement > ToGodot for & [ T ] {
443
- type Pass = crate :: meta:: ByValue ;
444
+ type Pass = meta:: ByValue ;
444
445
445
446
fn to_godot ( & self ) -> Self :: Via {
446
447
Array :: from ( * self )
@@ -461,7 +462,7 @@ macro_rules! impl_pointer_convert {
461
462
}
462
463
463
464
impl ToGodot for $Ptr {
464
- type Pass = crate :: meta:: ByValue ;
465
+ type Pass = meta:: ByValue ;
465
466
466
467
fn to_godot( & self ) -> Self :: Via {
467
468
* self as i64
0 commit comments