Trait AsObjectArg
pub trait AsObjectArg<T>{ }
Expand description
Objects that can be passed as arguments to Godot engine functions.
This trait is implemented for shared references in multiple ways:
&Gd<T>
to pass objects. Subclasses ofT
are explicitly supported.Option<&Gd<T>>
, to pass optional objects.None
is mapped to a null argument.Gd::null_arg()
, to passnull
arguments without usingOption
.
Note that AsObjectArg
is very similar to the more general AsArg
trait. The two may be merged in the future.
§Nullability
The GDExtension API does not inform about nullability of its function parameters. It is up to you to verify that the arguments you pass
are only null when this is allowed. Doing this wrong should be safe, but can lead to the function call failing.
§Different argument types
Currently, the trait requires pass-by-ref, which helps detect accidental cloning when interfacing with Godot APIs. Plus, it is more
consistent with the AsArg
trait (for strings, but also AsArg<Gd<T>>
as used in
Array::push()
and similar methods).
The following table lists the possible argument types and how you can pass them. Gd
is short for Gd<T>
.
Type | Closest accepted type | How to transform |
---|---|---|
Gd | &Gd | &arg |
&Gd | &Gd | arg |
&mut Gd | &Gd | &*arg |
Option<Gd> | Option<&Gd> | arg.as_ref() |
Option<&Gd> | Option<&Gd> | arg |
Option<&mut Gd> | Option<&Gd> | arg.as_deref() |
(null literal) | Gd::null_arg() |