Skip to content

Commit 12778bd

Browse files
committed
Rename ArgTarget -> ApiParam
1 parent e47c6b2 commit 12778bd

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

godot-core/src/builtin/collections/array.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::builtin::*;
1212
use crate::meta;
1313
use crate::meta::error::{ConvertError, FromGodotError, FromVariantError};
1414
use crate::meta::{
15-
ArgTarget, ArrayElement, ArrayTypeInfo, AsArg, CowArg, FromGodot, GodotConvert,
16-
GodotFfiVariant, GodotType, PropertyHintInfo, RefArg, ToGodot,
15+
ApiParam, ArrayElement, ArrayTypeInfo, AsArg, CowArg, FromGodot, GodotConvert, GodotFfiVariant,
16+
GodotType, PropertyHintInfo, RefArg, ToGodot,
1717
};
1818
use crate::registry::property::{Export, Var};
1919
use godot_ffi as sys;
@@ -944,7 +944,7 @@ impl<'r, T: ArrayElement> AsArg<Array<T>> for &'r Array<T> {
944944
}
945945
}
946946

947-
impl<T: ArrayElement> ArgTarget for Array<T> {
947+
impl<T: ArrayElement> ApiParam for Array<T> {
948948
type Arg<'v> = CowArg<'v, Self>;
949949

950950
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
@@ -1221,7 +1221,7 @@ impl<T: ArrayElement + ToGodot> Extend<T> for Array<T> {
12211221
// A faster implementation using `resize()` and direct pointer writes might still be possible.
12221222
// Note that this could technically also use iter(), since no moves need to happen (however Extend requires IntoIterator).
12231223
for item in iter.into_iter() {
1224-
self.push(ArgTarget::value_to_arg(item));
1224+
self.push(ApiParam::value_to_arg(item));
12251225
}
12261226
}
12271227
}

godot-core/src/builtin/collections/packed_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ macro_rules! impl_packed_array {
491491
// A faster implementation using `resize()` and direct pointer writes might still be
492492
// possible.
493493
for item in iter.into_iter() {
494-
self.push(meta::ArgTarget::value_to_arg(item));
494+
self.push(meta::ApiParam::value_to_arg(item));
495495
}
496496
}
497497
}

godot-core/src/meta/as_arg.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
use crate::builtin::{GString, NodePath, StringName};
9-
use crate::meta::CowArg;
9+
use crate::meta::{CowArg, GodotType};
1010
use std::ffi::CStr;
1111

1212
/// Implicit conversions for arguments passed to Godot APIs.
@@ -23,7 +23,7 @@ use std::ffi::CStr;
2323
/// Implicitly converting from `T` for by-ref builtins is explicitly not supported. This emphasizes that there is no need to consume the object,
2424
/// thus discourages unnecessary cloning.
2525
///
26-
/// If you need to pass owned values in generic code, you can use [`ArgTarget::value_to_arg()`].
26+
/// If you need to pass owned values in generic code, you can use [`ApiParam::value_to_arg()`].
2727
///
2828
/// # Performance for strings
2929
/// Godot has three string types: [`GString`], [`StringName`] and [`NodePath`]. Conversions between those three, as well as between `String` and
@@ -37,18 +37,25 @@ use std::ffi::CStr;
3737
///
3838
/// If you want to convert between Godot's string types for the sake of argument passing, each type provides an `arg()` method, such as
3939
/// [`GString::arg()`]. You cannot use this method in other contexts.
40+
///
41+
/// # Using the trait
42+
/// `AsArg` is meant to be used from the function call site, not the declaration site. If you declare a parameter as `impl AsArg<...>` yourself,
43+
/// you can only forward it as-is to a Godot API -- there are no stable APIs to access the inner object yet.
44+
///
45+
/// 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
46+
/// custom types. Classes are already supported through upcasting and [`AsObjectArg`][crate::obj::AsObjectArg].
4047
#[diagnostic::on_unimplemented(
4148
message = "Argument of type `{Self}` cannot be passed to an `impl AsArg<{T}>` parameter",
4249
note = "If you pass by value, consider borrowing instead.",
4350
note = "GString/StringName/NodePath aren't implicitly convertible for performance reasons; use their `arg()` method.",
4451
note = "See also `AsArg` docs: https://godot-rust.github.io/docs/gdext/master/godot/meta/trait.AsArg.html"
4552
)]
46-
pub trait AsArg<T: ArgTarget>
53+
pub trait AsArg<T: ApiParam>
4754
where
4855
Self: Sized,
4956
{
5057
#[doc(hidden)]
51-
fn into_arg<'r>(self) -> <T as ArgTarget>::Arg<'r>
58+
fn into_arg<'r>(self) -> <T as ApiParam>::Arg<'r>
5259
where
5360
Self: 'r;
5461
}
@@ -70,7 +77,7 @@ macro_rules! arg_into_ref {
7077
};
7178
($arg_variable:ident: $T:ty) => {
7279
let $arg_variable = $arg_variable.into_arg();
73-
let $arg_variable: &$T = $crate::meta::ArgTarget::arg_to_ref(&$arg_variable);
80+
let $arg_variable: &$T = $crate::meta::ApiParam::arg_to_ref(&$arg_variable);
7481
};
7582
}
7683

@@ -82,21 +89,21 @@ macro_rules! arg_into_owned {
8289
($arg_variable:ident) => {
8390
let $arg_variable = $arg_variable.into_arg();
8491
let $arg_variable = $arg_variable.cow_into_owned();
85-
// cow_into_owned() is not yet used generically; could be abstracted in ArgTarget::arg_to_owned() as well.
92+
// cow_into_owned() is not yet used generically; could be abstracted in ApiParam::arg_to_owned() as well.
8693
};
8794
}
8895

8996
#[macro_export]
9097
macro_rules! impl_asarg_by_value {
9198
($T:ty) => {
9299
impl $crate::meta::AsArg<$T> for $T {
93-
fn into_arg<'r>(self) -> <$T as $crate::meta::ArgTarget>::Arg<'r> {
100+
fn into_arg<'r>(self) -> <$T as $crate::meta::ApiParam>::Arg<'r> {
94101
// Moves value (but typically a Copy type).
95102
self
96103
}
97104
}
98105

99-
impl $crate::meta::ArgTarget for $T {
106+
impl $crate::meta::ApiParam for $T {
100107
type Arg<'v> = $T;
101108

102109
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
@@ -121,15 +128,15 @@ macro_rules! impl_asarg_by_ref {
121128
// Thus, keep `where` on same line.
122129
// type ArgType<'v> = &'v $T where Self: 'v;
123130

124-
fn into_arg<'cow>(self) -> <$T as $crate::meta::ArgTarget>::Arg<'cow>
131+
fn into_arg<'cow>(self) -> <$T as $crate::meta::ApiParam>::Arg<'cow>
125132
where
126133
'r: 'cow, // Original reference must be valid for at least as long as the returned cow.
127134
{
128135
$crate::meta::CowArg::Borrowed(self)
129136
}
130137
}
131138

132-
impl $crate::meta::ArgTarget for $T {
139+
impl $crate::meta::ApiParam for $T {
133140
type Arg<'v> = $crate::meta::CowArg<'v, $T>;
134141

135142
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
@@ -150,11 +157,11 @@ macro_rules! declare_arg_method {
150157
///
151158
/// # Generic bounds
152159
/// The bounds are implementation-defined and may change at any time. Do not use this function in a generic context requiring `T`
153-
/// -- use the `From` trait or [`ArgTarget`][crate::meta::ArgTarget] in that case.
160+
/// -- use the `From` trait or [`ApiParam`][crate::meta::ApiParam] in that case.
154161
pub fn arg<T>(&self) -> impl $crate::meta::AsArg<T>
155162
where
156163
for<'a> T: From<&'a Self>
157-
+ $crate::meta::ArgTarget<Arg<'a> = $crate::meta::CowArg<'a, T>>
164+
+ $crate::meta::ApiParam<Arg<'a> = $crate::meta::CowArg<'a, T>>
158165
+ 'a,
159166
{
160167
$crate::meta::CowArg::Owned(T::from(self))
@@ -171,7 +178,7 @@ macro_rules! declare_arg_method {
171178
/// This is necessary for packed array dispatching to different "inner" backend signatures.
172179
impl<'a, T> AsArg<T> for CowArg<'a, T>
173180
where
174-
for<'r> T: ArgTarget<Arg<'r> = CowArg<'r, T>> + 'r,
181+
for<'r> T: ApiParam<Arg<'r> = CowArg<'r, T>> + 'r,
175182
{
176183
fn into_arg<'r>(self) -> CowArg<'r, T>
177184
where
@@ -181,7 +188,7 @@ where
181188
}
182189
}
183190

184-
// impl<'a, T> ArgTarget for CowArg<'a, T> {
191+
// impl<'a, T> ApiParam for CowArg<'a, T> {
185192
// type Type<'v> = CowArg<'v, T>
186193
// where Self: 'v;
187194
// }
@@ -243,7 +250,8 @@ impl AsArg<NodePath> for &String {
243250
// ----------------------------------------------------------------------------------------------------------------------------------------------
244251

245252
/// Implemented for all parameter types `T` that are allowed to receive [impl `AsArg<T>`][AsArg].
246-
pub trait ArgTarget
253+
pub trait ApiParam: GodotType
254+
// GodotType bound not required right now, but conceptually should always be the case.
247255
where
248256
Self: Sized,
249257
{

godot-core/src/meta/cow_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'r, T> CowArg<'r, T> {
4747
}
4848
}
4949

50-
/// Exists for polymorphism in [`crate::meta::ArgTarget`].
50+
/// Exists for polymorphism in [`crate::meta::ApiParam`].
5151
///
5252
/// Necessary for generics in e.g. `Array<T>`, when accepting `impl AsArg<T>` parameters.
5353
///

godot-core/src/meta/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
162162
message = "`Array<T>` can only store element types supported in Godot arrays (no nesting).",
163163
label = "has invalid element type"
164164
)]
165-
pub trait ArrayElement: GodotType + ToGodot + FromGodot + sealed::Sealed + meta::ArgTarget {
165+
pub trait ArrayElement: GodotType + ToGodot + FromGodot + sealed::Sealed + meta::ApiParam {
166166
/// Returns the representation of this type as a type string.
167167
///
168168
/// Used for elements in arrays (the latter despite `ArrayElement` not having a direct relation).

godot-core/src/obj/gd.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::builtin::{Callable, NodePath, StringName, Variant};
1616
use crate::global::PropertyHint;
1717
use crate::meta::error::{ConvertError, FromFfiError};
1818
use crate::meta::{
19-
ArgTarget, ArrayElement, AsArg, CallContext, ClassName, CowArg, FromGodot, GodotConvert,
19+
ApiParam, ArrayElement, AsArg, CallContext, ClassName, CowArg, FromGodot, GodotConvert,
2020
GodotType, PropertyHintInfo, RefArg, ToGodot,
2121
};
2222
use crate::obj::{
@@ -781,7 +781,7 @@ impl<'r, T: GodotClass> AsArg<Gd<T>> for &'r Gd<T> {
781781
}
782782
}
783783

784-
impl<T: GodotClass> ArgTarget for Gd<T> {
784+
impl<T: GodotClass> ApiParam for Gd<T> {
785785
type Arg<'v> = CowArg<'v, Gd<T>>;
786786

787787
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
@@ -803,7 +803,7 @@ impl<'r, T: GodotClass> AsArg<Option<Gd<T>>> for Option<&'r Gd<T>> {
803803
}
804804
}
805805

806-
impl<T: GodotClass> ArgTarget for Option<Gd<T>> {
806+
impl<T: GodotClass> ApiParam for Option<Gd<T>> {
807807
type Arg<'v> = CowArg<'v, Option<Gd<T>>>;
808808

809809
fn value_to_arg<'v>(self) -> Self::Arg<'v> {

0 commit comments

Comments
 (0)