@@ -143,6 +143,7 @@ where
143
143
T : Inherits < Base > ,
144
144
Base : GodotClass ,
145
145
{
146
+ //noinspection RsConstantConditionIf - false positive in IDE for `T::IS_SAME_CLASS`.
146
147
fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Gd < Base > >
147
148
where
148
149
Self : ' arg ,
@@ -199,7 +200,7 @@ where
199
200
}
200
201
}
201
202
202
- // Convert `DynGd` -> `Gd` (with upcast).
203
+ /// Convert `DynGd` -> `Gd` (with upcast).
203
204
impl < T , D , Base > AsArg < Gd < Base > > for & DynGd < T , D >
204
205
where
205
206
T : Inherits < Base > ,
@@ -223,9 +224,68 @@ where
223
224
}
224
225
}
225
226
227
+ // ----------------------------------------------------------------------------------------------------------------------------------------------
228
+ // Null arguments
229
+
230
+ /// Private struct for passing null arguments to optional object parameters.
231
+ ///
232
+ /// This struct implements `AsArg` for both `Option<Gd<T>>` and `Option<DynGd<T, D>>`, allowing [`Gd::null_arg()`] and [`DynGd::null_arg()`]
233
+ /// to share implementation.
234
+ ///
235
+ /// Not public, as `impl AsArg<...>` is used by `null_arg()` methods.
236
+ pub ( crate ) struct NullArg < T > ( pub std:: marker:: PhantomData < * mut T > ) ;
237
+
238
+ impl < T > AsArg < Option < Gd < T > > > for NullArg < T >
239
+ where
240
+ T : GodotClass ,
241
+ {
242
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < Gd < T > > >
243
+ where
244
+ Self : ' arg ,
245
+ {
246
+ CowArg :: Owned ( None )
247
+ }
248
+ }
249
+
250
+ impl < T , D > AsArg < Option < DynGd < T , D > > > for NullArg < T >
251
+ where
252
+ T : GodotClass ,
253
+ D : ?Sized + ' static ,
254
+ {
255
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < DynGd < T , D > > >
256
+ where
257
+ Self : ' arg ,
258
+ {
259
+ CowArg :: Owned ( None )
260
+ }
261
+ }
262
+
226
263
// ----------------------------------------------------------------------------------------------------------------------------------------------
227
264
// Optional object (Gd + DynGd) impls
228
265
266
+ /// Convert `&Gd` -> `Option<Gd>` (with upcast).
267
+ impl < T , Base > AsArg < Option < Gd < Base > > > for & Gd < T >
268
+ where
269
+ T : Inherits < Base > ,
270
+ Base : GodotClass + Bounds < Declarer = bounds:: DeclEngine > ,
271
+ {
272
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < Gd < Base > > >
273
+ where
274
+ Self : ' arg ,
275
+ {
276
+ // Upcasting to an owned value Gd<Base> requires cloning. Optimized path in into_ffi_arg().
277
+ CowArg :: Owned ( Some ( self . clone ( ) . upcast :: < Base > ( ) ) )
278
+ }
279
+
280
+ fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < Gd < Base > > >
281
+ where
282
+ Self : ' arg ,
283
+ {
284
+ let arg = ObjectArg :: from_gd ( self ) ;
285
+ FfiArg :: FfiObject ( arg)
286
+ }
287
+ }
288
+
229
289
/// Convert `Option<&Gd>` -> `Option<Gd>` (with upcast).
230
290
impl < T , Base > AsArg < Option < Gd < Base > > > for Option < & Gd < T > >
231
291
where
@@ -252,21 +312,22 @@ where
252
312
}
253
313
}
254
314
255
- /// Convert `&Gd ` -> `Option<Gd >` (with upcast).
256
- impl < T , Base > AsArg < Option < Gd < Base > > > for & Gd < T >
315
+ /// Convert `&DynGd ` -> `Option<DynGd >` (with upcast).
316
+ impl < T , D , Base > AsArg < Option < DynGd < Base , D > > > for & DynGd < T , D >
257
317
where
258
318
T : Inherits < Base > ,
319
+ D : ?Sized ,
259
320
Base : GodotClass + Bounds < Declarer = bounds:: DeclEngine > ,
260
321
{
261
- fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < Gd < Base > > >
322
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < DynGd < Base , D > > >
262
323
where
263
324
Self : ' arg ,
264
325
{
265
- // Upcasting to an owned value Gd <Base> requires cloning. Optimized path in into_ffi_arg().
266
- CowArg :: Owned ( Some ( self . clone ( ) . upcast :: < Base > ( ) ) )
326
+ // Upcasting to an owned value DynGd <Base, D > requires cloning. Optimized path in into_ffi_arg().
327
+ CowArg :: Owned ( Some ( self . clone ( ) . upcast ( ) ) )
267
328
}
268
329
269
- fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < Gd < Base > > >
330
+ fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < DynGd < Base , D > > >
270
331
where
271
332
Self : ' arg ,
272
333
{
@@ -299,6 +360,34 @@ where
299
360
}
300
361
}
301
362
363
+ /// Convert `Option<&DynGd>` -> `Option<DynGd>` (with upcast).
364
+ impl < T , D , Base > AsArg < Option < DynGd < Base , D > > > for Option < & DynGd < T , D > >
365
+ where
366
+ T : Inherits < Base > ,
367
+ D : ?Sized ,
368
+ Base : GodotClass + Bounds < Declarer = bounds:: DeclEngine > ,
369
+ {
370
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < DynGd < Base , D > > >
371
+ where
372
+ Self : ' arg ,
373
+ {
374
+ // Upcasting to an owned value Gd<Base> requires cloning. Optimized path in into_ffi_arg().
375
+ match self {
376
+ Some ( gd_ref) => AsArg :: into_arg ( gd_ref) ,
377
+ None => CowArg :: Owned ( None ) ,
378
+ }
379
+ }
380
+
381
+ fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < DynGd < Base , D > > >
382
+ where
383
+ Self : ' arg ,
384
+ {
385
+ let option_gd: Option < & Gd < T > > = self . map ( |v| & * * v) ; // as_deref() not working.
386
+ let arg = ObjectArg :: from_option_gd ( option_gd) ;
387
+ FfiArg :: FfiObject ( arg)
388
+ }
389
+ }
390
+
302
391
// ----------------------------------------------------------------------------------------------------------------------------------------------
303
392
// Public helper functions (T|&T -> AsArg)
304
393
0 commit comments