@@ -19,11 +19,14 @@ use std::ffi::CStr;
19
19
/// - `&T` for by-ref builtins: `GString`, `Array`, `Dictionary`, `Packed*Array`, `Variant`...
20
20
/// - `&str`, `&String` additionally for string types `GString`, `StringName`, `NodePath`.
21
21
///
22
+ /// See also the [`AsObjectArg`][crate::meta::AsObjectArg] trait which is specialized for object arguments. It may be merged with `AsArg`
23
+ /// in the future.
24
+ ///
22
25
/// # Pass by value
23
26
/// Implicitly converting from `T` for by-ref builtins is explicitly not supported. This emphasizes that there is no need to consume the object,
24
27
/// thus discourages unnecessary cloning.
25
28
///
26
- /// If you need to pass owned values in generic code, you can use [`ApiParam ::owned_to_arg()`].
29
+ /// If you need to pass owned values in generic code, you can use [`ParamType ::owned_to_arg()`].
27
30
///
28
31
/// # Performance for strings
29
32
/// Godot has three string types: [`GString`], [`StringName`] and [`NodePath`]. Conversions between those three, as well as between `String` and
@@ -43,19 +46,19 @@ use std::ffi::CStr;
43
46
/// you can only forward it as-is to a Godot API -- there are no stable APIs to access the inner object yet.
44
47
///
45
48
/// 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].
49
+ /// custom types. Classes are already supported through upcasting and [`AsObjectArg`][crate::meta ::AsObjectArg].
47
50
#[ diagnostic:: on_unimplemented(
48
51
message = "Argument of type `{Self}` cannot be passed to an `impl AsArg<{T}>` parameter" ,
49
52
note = "If you pass by value, consider borrowing instead." ,
50
53
note = "GString/StringName/NodePath aren't implicitly convertible for performance reasons; use their `arg()` method." ,
51
54
note = "See also `AsArg` docs: https://godot-rust.github.io/docs/gdext/master/godot/meta/trait.AsArg.html"
52
55
) ]
53
- pub trait AsArg < T : ApiParam >
56
+ pub trait AsArg < T : ParamType >
54
57
where
55
58
Self : Sized ,
56
59
{
57
60
#[ doc( hidden) ]
58
- fn into_arg < ' r > ( self ) -> <T as ApiParam >:: Arg < ' r >
61
+ fn into_arg < ' r > ( self ) -> <T as ParamType >:: Arg < ' r >
59
62
where
60
63
Self : ' r ;
61
64
}
@@ -77,7 +80,7 @@ macro_rules! arg_into_ref {
77
80
} ;
78
81
( $arg_variable: ident: $T: ty) => {
79
82
let $arg_variable = $arg_variable. into_arg( ) ;
80
- let $arg_variable: & $T = $crate:: meta:: ApiParam :: arg_to_ref( & $arg_variable) ;
83
+ let $arg_variable: & $T = $crate:: meta:: ParamType :: arg_to_ref( & $arg_variable) ;
81
84
} ;
82
85
}
83
86
@@ -89,21 +92,21 @@ macro_rules! arg_into_owned {
89
92
( $arg_variable: ident) => {
90
93
let $arg_variable = $arg_variable. into_arg( ) ;
91
94
let $arg_variable = $arg_variable. cow_into_owned( ) ;
92
- // cow_into_owned() is not yet used generically; could be abstracted in ApiParam ::arg_to_owned() as well.
95
+ // cow_into_owned() is not yet used generically; could be abstracted in ParamType ::arg_to_owned() as well.
93
96
} ;
94
97
}
95
98
96
99
#[ macro_export]
97
100
macro_rules! impl_asarg_by_value {
98
101
( $T: ty) => {
99
102
impl $crate:: meta:: AsArg <$T> for $T {
100
- fn into_arg<' r>( self ) -> <$T as $crate:: meta:: ApiParam >:: Arg <' r> {
103
+ fn into_arg<' r>( self ) -> <$T as $crate:: meta:: ParamType >:: Arg <' r> {
101
104
// Moves value (but typically a Copy type).
102
105
self
103
106
}
104
107
}
105
108
106
- impl $crate:: meta:: ApiParam for $T {
109
+ impl $crate:: meta:: ParamType for $T {
107
110
type Arg <' v> = $T;
108
111
109
112
fn owned_to_arg<' v>( self ) -> Self :: Arg <' v> {
@@ -128,15 +131,15 @@ macro_rules! impl_asarg_by_ref {
128
131
// Thus, keep `where` on same line.
129
132
// type ArgType<'v> = &'v $T where Self: 'v;
130
133
131
- fn into_arg<' cow>( self ) -> <$T as $crate:: meta:: ApiParam >:: Arg <' cow>
134
+ fn into_arg<' cow>( self ) -> <$T as $crate:: meta:: ParamType >:: Arg <' cow>
132
135
where
133
136
' r: ' cow, // Original reference must be valid for at least as long as the returned cow.
134
137
{
135
138
$crate:: meta:: CowArg :: Borrowed ( self )
136
139
}
137
140
}
138
141
139
- impl $crate:: meta:: ApiParam for $T {
142
+ impl $crate:: meta:: ParamType for $T {
140
143
type Arg <' v> = $crate:: meta:: CowArg <' v, $T>;
141
144
142
145
fn owned_to_arg<' v>( self ) -> Self :: Arg <' v> {
@@ -157,11 +160,11 @@ macro_rules! declare_arg_method {
157
160
///
158
161
/// # Generic bounds
159
162
/// The bounds are implementation-defined and may change at any time. Do not use this function in a generic context requiring `T`
160
- /// -- use the `From` trait or [`ApiParam `][crate::meta::ApiParam ] in that case.
163
+ /// -- use the `From` trait or [`ParamType `][crate::meta::ParamType ] in that case.
161
164
pub fn arg<T >( & self ) -> impl $crate:: meta:: AsArg <T >
162
165
where
163
166
for <' a> T : From <& ' a Self >
164
- + $crate:: meta:: ApiParam <Arg <' a> = $crate:: meta:: CowArg <' a, T >>
167
+ + $crate:: meta:: ParamType <Arg <' a> = $crate:: meta:: CowArg <' a, T >>
165
168
+ ' a,
166
169
{
167
170
$crate:: meta:: CowArg :: Owned ( T :: from( self ) )
@@ -178,7 +181,7 @@ macro_rules! declare_arg_method {
178
181
/// This is necessary for packed array dispatching to different "inner" backend signatures.
179
182
impl < ' a , T > AsArg < T > for CowArg < ' a , T >
180
183
where
181
- for < ' r > T : ApiParam < Arg < ' r > = CowArg < ' r , T > > + ' r ,
184
+ for < ' r > T : ParamType < Arg < ' r > = CowArg < ' r , T > > + ' r ,
182
185
{
183
186
fn into_arg < ' r > ( self ) -> CowArg < ' r , T >
184
187
where
@@ -188,7 +191,7 @@ where
188
191
}
189
192
}
190
193
191
- // impl<'a, T> ApiParam for CowArg<'a, T> {
194
+ // impl<'a, T> ParamType for CowArg<'a, T> {
192
195
// type Type<'v> = CowArg<'v, T>
193
196
// where Self: 'v;
194
197
// }
@@ -250,7 +253,7 @@ impl AsArg<NodePath> for &String {
250
253
// ----------------------------------------------------------------------------------------------------------------------------------------------
251
254
252
255
/// Implemented for all parameter types `T` that are allowed to receive [impl `AsArg<T>`][AsArg].
253
- pub trait ApiParam : GodotType
256
+ pub trait ParamType : GodotType
254
257
// GodotType bound not required right now, but conceptually should always be the case.
255
258
{
256
259
/// Canonical argument passing type, either `T` or an internally-used CoW type.
0 commit comments