Skip to content

Commit 7fa6f07

Browse files
committed
Update AsArg and ParamType documentation to reflect changes
1 parent 6010819 commit 7fa6f07

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

godot-core/src/meta/args/as_arg.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use std::ffi::CStr;
1616
/// this trait is implemented more conservatively.
1717
///
1818
/// As a result, `AsArg<T>` is currently only implemented for certain argument types:
19-
/// - `T` for by-value builtins (typically `Copy`): `i32`, `bool`, `Vector3`, `Transform2D`, ...
20-
/// - `&T` for by-ref builtins: `GString`, `Array`, `Dictionary`, `Packed*Array`, `Variant`...
19+
/// - `T` for by-value built-ins (typically `Copy`): `i32`, `bool`, `Vector3`, `Transform2D`, ...
20+
/// - `&T` for by-ref built-ins: `GString`, `Array`, `Dictionary`, `Packed*Array`, `Variant`...
2121
/// - `&str`, `&String` additionally for string types `GString`, `StringName`, `NodePath`.
2222
///
2323
/// See also the [`AsObjectArg`][crate::meta::AsObjectArg] trait which is specialized for object arguments. It may be merged with `AsArg`
2424
/// in the future.
2525
///
2626
/// # Pass by value
27-
/// Implicitly converting from `T` for by-ref builtins is explicitly not supported. This emphasizes that there is no need to consume the object,
27+
/// Implicitly converting from `T` for by-ref built-ins is explicitly not supported. This emphasizes that there is no need to consume the object,
2828
/// thus discourages unnecessary cloning.
2929
///
3030
/// # Performance for strings
@@ -44,8 +44,7 @@ use std::ffi::CStr;
4444
/// `AsArg` is meant to be used from the function call site, not the declaration site. If you declare a parameter as `impl AsArg<...>` yourself,
4545
/// you can only forward it as-is to a Godot API -- there are no stable APIs to access the inner object yet.
4646
///
47-
/// Furthermore, there is currently no benefit in implementing `AsArg` for your own types, as it's only used by Godot APIs which don't accept
48-
/// custom types. Classes are already supported through upcasting and [`AsObjectArg`][crate::meta::AsObjectArg].
47+
/// If you want to pass your own types to a Godot API i.e. to emit a signal, you should implement the [`ParamType`] trait.
4948
#[diagnostic::on_unimplemented(
5049
message = "Argument of type `{Self}` cannot be passed to an `impl AsArg<{T}>` parameter",
5150
note = "if you pass by value, consider borrowing instead.",
@@ -259,6 +258,10 @@ impl AsArg<NodePath> for &String {
259258
// ----------------------------------------------------------------------------------------------------------------------------------------------
260259

261260
/// Implemented for all parameter types `T` that are allowed to receive [impl `AsArg<T>`][AsArg].
261+
///
262+
/// **Deprecated**: This trait is considered deprecated and will be removed in 0.4. It is still required to be implemented by types that should
263+
/// be passed `AsArg` in the current version, though.
264+
//
262265
// ParamType used to be a subtrait of GodotType, but this can be too restrictive. For example, DynGd is not a "Godot canonical type"
263266
// (GodotType), however it's still useful to store it in arrays -- which requires AsArg and subsequently ParamType.
264267
//

godot-core/src/meta/traits.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ pub trait GodotFfiVariant: Sized + GodotFfi {
3636
//
3737
// Unlike `GodotFfi`, types implementing this trait don't need to fully represent its corresponding Godot
3838
// type. For instance [`i32`] does not implement `GodotFfi` because it cannot represent all values of
39-
// Godot's `int` type, however it does implement `GodotType` because we can set the metadata of values with
39+
// Godot's `int` type, however it does implement `GodotType` because we can set the meta-data of values with
4040
// this type to indicate that they are 32 bits large.
4141
pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
42-
// 'static is not technically required, but it simplifies a few things (limits e.g. ObjectArg).
42+
// 'static is not technically required, but it simplifies a few things (limits e.g. `ObjectArg`).
4343
{
4444
// Value type for this type's FFI representation.
4545
#[doc(hidden)]
@@ -122,7 +122,7 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
122122
///
123123
/// Examples:
124124
/// - `MyClass` for objects
125-
/// - `StringName`, `AABB` or `int` for builtins
125+
/// - `StringName`, `AABB` or `int` for built-ins
126126
/// - `Array` for arrays
127127
#[doc(hidden)]
128128
fn godot_type_name() -> String;
@@ -131,7 +131,7 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
131131
///
132132
/// Returning false only means that this is not a special case, not that it cannot be `None`. Regular checks are expected to run afterward.
133133
///
134-
/// This exists only for varcalls and serves a similar purpose as `GodotNullableFfi::is_null()` (although that handles general cases).
134+
/// This exists only for var-calls and serves a similar purpose as `GodotNullableFfi::is_null()` (although that handles general cases).
135135
#[doc(hidden)]
136136
fn qualifies_as_special_none(_from_variant: &Variant) -> bool {
137137
false
@@ -164,14 +164,14 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
164164
/// Also, keep in mind that Godot uses `Variant` for each element. If performance matters and you have small element types such as `u8`,
165165
/// consider using packed arrays (e.g. `PackedByteArray`) instead.
166166
//
167-
// TODO: The ParamType super trait is no longer needed and can be removed in 0.4. We are only keeping it for backwards compatebility.
167+
// TODO: The `ParamType` super trait is no longer needed and can be removed in 0.4. We are only keeping it for backwards compatibility.
168168
#[diagnostic::on_unimplemented(
169169
message = "`Array<T>` can only store element types supported in Godot arrays (no nesting).",
170170
label = "has invalid element type"
171171
)]
172172
pub trait ArrayElement: ToGodot + FromGodot + sealed::Sealed + ParamType + 'static {
173-
// Note: several indirections in ArrayElement and the global `element_*` functions go through `GodotConvert::Via`,
174-
// to not require Self: GodotType. What matters is how array elements map to Godot on the FFI level (GodotType trait).
173+
// Note: several indirections in `ArrayElement` and the global `element_*` functions go through `GodotConvert::Via`,
174+
// to not require Self: `GodotType`. What matters is how array elements map to Godot on the FFI level (`GodotType` trait).
175175

176176
/// Returns the representation of this type as a type string, e.g. `"4:"` for string, or `"24:34/MyClass"` for objects.
177177
///

0 commit comments

Comments
 (0)