@@ -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 > ,
@@ -226,6 +227,29 @@ where
226
227
// ----------------------------------------------------------------------------------------------------------------------------------------------
227
228
// Optional object (Gd + DynGd) impls
228
229
230
+ /// Convert `&Gd` -> `Option<Gd>` (with upcast).
231
+ impl < T , Base > AsArg < Option < Gd < Base > > > for & Gd < T >
232
+ where
233
+ T : Inherits < Base > ,
234
+ Base : GodotClass + Bounds < Declarer = bounds:: DeclEngine > ,
235
+ {
236
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < Gd < Base > > >
237
+ where
238
+ Self : ' arg ,
239
+ {
240
+ // Upcasting to an owned value Gd<Base> requires cloning. Optimized path in into_ffi_arg().
241
+ CowArg :: Owned ( Some ( self . clone ( ) . upcast :: < Base > ( ) ) )
242
+ }
243
+
244
+ fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < Gd < Base > > >
245
+ where
246
+ Self : ' arg ,
247
+ {
248
+ let arg = ObjectArg :: from_gd ( self ) ;
249
+ FfiArg :: FfiObject ( arg)
250
+ }
251
+ }
252
+
229
253
/// Convert `Option<&Gd>` -> `Option<Gd>` (with upcast).
230
254
impl < T , Base > AsArg < Option < Gd < Base > > > for Option < & Gd < T > >
231
255
where
@@ -252,21 +276,22 @@ where
252
276
}
253
277
}
254
278
255
- /// Convert `&Gd ` -> `Option<Gd >` (with upcast).
256
- impl < T , Base > AsArg < Option < Gd < Base > > > for & Gd < T >
279
+ /// Convert `&DynGd ` -> `Option<DynGd >` (with upcast).
280
+ impl < T , D , Base > AsArg < Option < DynGd < Base , D > > > for & DynGd < T , D >
257
281
where
258
282
T : Inherits < Base > ,
283
+ D : ?Sized ,
259
284
Base : GodotClass + Bounds < Declarer = bounds:: DeclEngine > ,
260
285
{
261
- fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < Gd < Base > > >
286
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < DynGd < Base , D > > >
262
287
where
263
288
Self : ' arg ,
264
289
{
265
- // Upcasting to an owned value Gd <Base> requires cloning. Optimized path in into_ffi_arg().
266
- CowArg :: Owned ( Some ( self . clone ( ) . upcast :: < Base > ( ) ) )
290
+ // Upcasting to an owned value DynGd <Base, D > requires cloning. Optimized path in into_ffi_arg().
291
+ CowArg :: Owned ( Some ( self . clone ( ) . upcast ( ) ) )
267
292
}
268
293
269
- fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < Gd < Base > > >
294
+ fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < DynGd < Base , D > > >
270
295
where
271
296
Self : ' arg ,
272
297
{
@@ -299,6 +324,34 @@ where
299
324
}
300
325
}
301
326
327
+ /// Convert `Option<&DynGd>` -> `Option<DynGd>` (with upcast).
328
+ impl < T , D , Base > AsArg < Option < DynGd < Base , D > > > for Option < & DynGd < T , D > >
329
+ where
330
+ T : Inherits < Base > ,
331
+ D : ?Sized ,
332
+ Base : GodotClass + Bounds < Declarer = bounds:: DeclEngine > ,
333
+ {
334
+ fn into_arg < ' arg > ( self ) -> CowArg < ' arg , Option < DynGd < Base , D > > >
335
+ where
336
+ Self : ' arg ,
337
+ {
338
+ // Upcasting to an owned value Gd<Base> requires cloning. Optimized path in into_ffi_arg().
339
+ match self {
340
+ Some ( gd_ref) => AsArg :: into_arg ( gd_ref) ,
341
+ None => CowArg :: Owned ( None ) ,
342
+ }
343
+ }
344
+
345
+ fn into_ffi_arg < ' arg > ( self ) -> FfiArg < ' arg , Option < DynGd < Base , D > > >
346
+ where
347
+ Self : ' arg ,
348
+ {
349
+ let option_gd: Option < & Gd < T > > = self . map ( |v| & * * v) ; // as_deref() not working.
350
+ let arg = ObjectArg :: from_option_gd ( option_gd) ;
351
+ FfiArg :: FfiObject ( arg)
352
+ }
353
+ }
354
+
302
355
// ----------------------------------------------------------------------------------------------------------------------------------------------
303
356
// Public helper functions (T|&T -> AsArg)
304
357
0 commit comments