@@ -15,16 +15,33 @@ use std::ptr;
15
15
16
16
/// Objects that can be passed as arguments to Godot engine functions.
17
17
///
18
- /// This trait is implemented for the following types :
19
- /// - [`Gd<T>`] and `&Gd<T>`, to pass objects. Subclasses of `T` are explicitly supported.
20
- /// - [`Option<Gd<T>>`] and ` Option<&Gd<T>>` , to pass optional objects. `None` is mapped to a null argument.
18
+ /// This trait is implemented for **shared references** in multiple ways :
19
+ /// - [`& Gd<T>`][crate::obj::Gd] to pass objects. Subclasses of `T` are explicitly supported.
20
+ /// - [`Option<& Gd<T>>`][ Option] , to pass optional objects. `None` is mapped to a null argument.
21
21
/// - [`Gd::null_arg()`], to pass `null` arguments without using `Option`.
22
22
///
23
23
/// # Nullability
24
24
/// <div class="warning">
25
25
/// The GDExtension API does not inform about nullability of its function parameters. It is up to you to verify that the arguments you pass
26
26
/// are only null when this is allowed. Doing this wrong should be safe, but can lead to the function call failing.
27
27
/// </div>
28
+ ///
29
+ /// # Different argument types
30
+ /// Currently, the trait requires pass-by-ref, which helps detect accidental cloning when interfacing with Godot APIs. Plus, it is more
31
+ /// consistent with the [`AsArg`][crate::meta::AsArg] trait (for strings, but also `AsArg<Gd<T>>` as used in
32
+ /// [`Array::push()`][crate::builtin::Array::push] and similar methods).
33
+ ///
34
+ /// The following table lists the possible argument types and how you can pass them. `Gd` is short for `Gd<T>`.
35
+ ///
36
+ /// | Type | Closest accepted type | How to transform |
37
+ /// |-------------------|-----------------------|------------------|
38
+ /// | `Gd` | `&Gd` | `&arg` |
39
+ /// | `&Gd` | `&Gd` | `arg` |
40
+ /// | `&mut Gd` | `&Gd` | `&*arg` |
41
+ /// | `Option<Gd>` | `Option<&Gd>` | `arg.as_ref()` |
42
+ /// | `Option<&Gd>` | `Option<&Gd>` | `arg` |
43
+ /// | `Option<&mut Gd>` | `Option<&Gd>` | `arg.as_deref()` |
44
+ /// | (null literal) | | `Gd::null_arg()` |
28
45
#[ diagnostic:: on_unimplemented(
29
46
message = "Argument of type `{Self}` cannot be passed to an `impl AsObjectArg<{T}>` parameter" ,
30
47
note = "If you pass by value, consider borrowing instead." ,
0 commit comments