Skip to content

Commit 1075c12

Browse files
TitanNanoBromeon
authored andcommitted
Eliminate ParamType entirely
1 parent 4e0e5a6 commit 1075c12

File tree

6 files changed

+25
-69
lines changed

6 files changed

+25
-69
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::{cmp, fmt};
1111
use crate::builtin::*;
1212
use crate::meta;
1313
use crate::meta::error::{ConvertError, FromGodotError, FromVariantError};
14+
#[expect(deprecated)]
1415
use crate::meta::{
1516
element_godot_type_name, element_variant_type, ArrayElement, ArrayTypeInfo, AsArg, ClassName,
1617
CowArg, FromGodot, GodotConvert, GodotFfiVariant, GodotType, ParamType, PropertyHintInfo,
@@ -675,7 +676,7 @@ impl<T: ArrayElement> Array<T> {
675676
// We need one dummy element of type T, because Godot's bsearch_custom() checks types (so Variant::nil() can't be passed).
676677
// Optimization: roundtrip Variant -> T -> Variant could be avoided, but anyone needing speed would use Rust binary search...
677678
let ignored_value = self.at(0);
678-
let ignored_value = <T as ParamType>::owned_to_arg(ignored_value);
679+
let ignored_value = AsArg::into_arg(&ignored_value);
679680

680681
let godot_comparator = |args: &[&Variant]| {
681682
let value = T::from_variant(args[0]);
@@ -1118,20 +1119,13 @@ unsafe impl<T: ArrayElement> GodotFfi for Array<T> {
11181119
// Only implement for untyped arrays; typed arrays cannot be nested in Godot.
11191120
impl ArrayElement for VariantArray {}
11201121

1122+
#[expect(deprecated)]
11211123
impl<T: ArrayElement> ParamType for Array<T> {
11221124
type Arg<'v> = CowArg<'v, Self>;
11231125

11241126
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
11251127
CowArg::Owned(self)
11261128
}
1127-
1128-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self {
1129-
arg.cow_as_ref()
1130-
}
1131-
1132-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self {
1133-
arg.cow_into_owned()
1134-
}
11351129
}
11361130

11371131
impl<T: ArrayElement> GodotConvert for Array<T> {
@@ -1427,15 +1421,15 @@ impl<T: ArrayElement + ToGodot> FromIterator<T> for Array<T> {
14271421
}
14281422

14291423
/// Extends a `Array` with the contents of an iterator.
1430-
impl<T: ArrayElement + ToGodot> Extend<T> for Array<T> {
1424+
impl<T: ArrayElement> Extend<T> for Array<T> {
14311425
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
14321426
// Unfortunately the GDExtension API does not offer the equivalent of `Vec::reserve`.
14331427
// Otherwise, we could use it to pre-allocate based on `iter.size_hint()`.
14341428
//
14351429
// A faster implementation using `resize()` and direct pointer writes might still be possible.
14361430
// Note that this could technically also use iter(), since no moves need to happen (however Extend requires IntoIterator).
14371431
for item in iter.into_iter() {
1438-
self.push(ParamType::owned_to_arg(item));
1432+
self.push(AsArg::into_arg(&item));
14391433
}
14401434
}
14411435
}

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ use std::ffi::CStr;
2626
/// Implicitly converting from `T` for by-ref builtins is explicitly not supported. This emphasizes that there is no need to consume the object,
2727
/// thus discourages unnecessary cloning.
2828
///
29-
/// If you need to pass owned values in generic code, you can use [`ParamType::owned_to_arg()`].
30-
///
3129
/// # Performance for strings
3230
/// Godot has three string types: [`GString`], [`StringName`] and [`NodePath`]. Conversions between those three, as well as between `String` and
3331
/// them, is generally expensive because of allocations, re-encoding, validations, hashing, etc. While this doesn't matter for a few strings
@@ -130,41 +128,27 @@ macro_rules! arg_into_owned {
130128
#[macro_export]
131129
macro_rules! impl_asarg_by_value {
132130
($T:ty) => {
131+
#[expect(deprecated)]
133132
impl $crate::meta::ParamType for $T {
134133
type Arg<'v> = $T;
135134

136135
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
137136
self
138137
}
139-
140-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self {
141-
arg
142-
}
143-
144-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self {
145-
arg
146-
}
147138
}
148139
};
149140
}
150141

151142
#[macro_export]
152143
macro_rules! impl_asarg_by_ref {
153144
($T:ty) => {
145+
#[expect(deprecated)]
154146
impl $crate::meta::ParamType for $T {
155147
type Arg<'v> = $crate::meta::CowArg<'v, $T>;
156148

157149
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
158150
$crate::meta::CowArg::Owned(self)
159151
}
160-
161-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self {
162-
arg.cow_as_ref()
163-
}
164-
165-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self {
166-
arg.cow_into_owned()
167-
}
168152
}
169153
};
170154
}
@@ -180,7 +164,7 @@ macro_rules! declare_arg_method {
180164
pub fn arg<T>(&self) -> impl $crate::meta::AsArg<T>
181165
where
182166
for<'a> T: From<&'a Self>
183-
+ $crate::meta::ParamType<Arg<'a> = $crate::meta::CowArg<'a, T>>
167+
+ $crate::meta::ToGodot
184168
+ 'a,
185169
{
186170
$crate::meta::CowArg::Owned(T::from(self))
@@ -271,6 +255,10 @@ impl AsArg<NodePath> for &String {
271255
/// Implemented for all parameter types `T` that are allowed to receive [impl `AsArg<T>`][AsArg].
272256
// ParamType used to be a subtrait of GodotType, but this can be too restrictive. For example, DynGd is not a "Godot canonical type"
273257
// (GodotType), however it's still useful to store it in arrays -- which requires AsArg and subsequently ParamType.
258+
#[deprecated(
259+
since = "0.3.2",
260+
note = "This trait is no longer needed and will be removed in 0.4"
261+
)]
274262
pub trait ParamType: sealed::Sealed + Sized + 'static + ToGodot
275263
// GodotType bound not required right now, but conceptually should always be the case.
276264
{
@@ -290,16 +278,4 @@ pub trait ParamType: sealed::Sealed + Sized + 'static + ToGodot
290278
///
291279
/// You should not rely on the exact return type, as it may change in future versions; treat it like `impl AsArg<Self>`.
292280
fn owned_to_arg<'v>(self) -> Self::Arg<'v>;
293-
294-
/// Converts an argument to a shared reference.
295-
///
296-
/// Useful in generic contexts where you need to extract a reference of an argument, independently of how it is passed.
297-
#[doc(hidden)] // for now, users are encouraged to use only call-site of impl AsArg; declaration-site may still develop.
298-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self;
299-
300-
/// Clones an argument into an owned value.
301-
///
302-
/// Useful in generic contexts where you need to extract a value of an argument, independently of how it is passed.
303-
#[doc(hidden)] // for now, users are encouraged to use only call-site of impl AsArg; declaration-site may still develop.
304-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self;
305281
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod ref_arg;
1313
// ----------------------------------------------------------------------------------------------------------------------------------------------
1414
// Public APIs
1515

16+
#[expect(deprecated)]
1617
pub use as_arg::{AsArg, ParamType};
1718
pub use object_arg::AsObjectArg;
1819
pub use ref_arg::RefArg;

godot-core/src/meta/traits.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
use crate::builtin::{Variant, VariantType};
99
use crate::global::PropertyUsageFlags;
1010
use crate::meta::error::ConvertError;
11+
#[expect(deprecated)]
1112
use crate::meta::{
12-
sealed, ClassName, FromGodot, GodotConvert, PropertyHintInfo, PropertyInfo, ToGodot,
13+
sealed, ClassName, FromGodot, GodotConvert, ParamType, PropertyHintInfo, PropertyInfo, ToGodot,
1314
};
1415
use crate::registry::method::MethodParamOrReturnInfo;
1516
use godot_ffi as sys;
1617

1718
// Re-export sys traits in this module, so all are in one place.
19+
use crate::builtin;
1820
use crate::registry::property::builtin_type_string;
19-
use crate::{builtin, meta};
2021
pub use sys::{GodotFfi, GodotNullableFfi};
2122

2223
/// Conversion of [`GodotFfi`] types to/from [`Variant`].
@@ -163,11 +164,14 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
163164
///
164165
/// Also, keep in mind that Godot uses `Variant` for each element. If performance matters and you have small element types such as `u8`,
165166
/// consider using packed arrays (e.g. `PackedByteArray`) instead.
167+
//
168+
// TODO: The ParamType super trait is no longer needed and can be removed in 0.4. We are only keeping it for backwards compatebility.
166169
#[diagnostic::on_unimplemented(
167170
message = "`Array<T>` can only store element types supported in Godot arrays (no nesting).",
168171
label = "has invalid element type"
169172
)]
170-
pub trait ArrayElement: ToGodot + FromGodot + sealed::Sealed + meta::ParamType {
173+
#[expect(deprecated)]
174+
pub trait ArrayElement: ToGodot + FromGodot + sealed::Sealed + ParamType + 'static {
171175
// Note: several indirections in ArrayElement and the global `element_*` functions go through `GodotConvert::Via`,
172176
// to not require Self: GodotType. What matters is how array elements map to Godot on the FFI level (GodotType trait).
173177

godot-core/src/obj/dyn_gd.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ where
547547
}
548548
*/
549549

550+
#[expect(deprecated)]
550551
impl<T, D> meta::ParamType for DynGd<T, D>
551552
where
552553
T: GodotClass,
@@ -557,14 +558,6 @@ where
557558
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
558559
meta::CowArg::Owned(self)
559560
}
560-
561-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self {
562-
arg.cow_as_ref()
563-
}
564-
565-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self {
566-
arg.cow_into_owned()
567-
}
568561
}
569562

570563
impl<T, D> meta::ArrayElement for DynGd<T, D>

godot-core/src/obj/gd.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use sys::{static_assert_eq_size_align, SysPtr as _};
1313

1414
use crate::builtin::{Callable, NodePath, StringName, Variant};
1515
use crate::meta::error::{ConvertError, FromFfiError};
16+
17+
#[expect(deprecated)]
1618
use crate::meta::{
1719
ArrayElement, AsArg, CallContext, ClassName, CowArg, FromGodot, GodotConvert, GodotType,
1820
ParamType, PropertyHintInfo, RefArg, ToGodot,
@@ -866,20 +868,13 @@ where
866868
}
867869
*/
868870

871+
#[expect(deprecated)]
869872
impl<T: GodotClass> ParamType for Gd<T> {
870873
type Arg<'v> = CowArg<'v, Gd<T>>;
871874

872875
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
873876
CowArg::Owned(self)
874877
}
875-
876-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self {
877-
arg.cow_as_ref()
878-
}
879-
880-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self {
881-
arg.cow_into_owned()
882-
}
883878
}
884879

885880
impl<T: GodotClass> AsArg<Option<Gd<T>>> for Option<&Gd<T>> {
@@ -892,20 +887,13 @@ impl<T: GodotClass> AsArg<Option<Gd<T>>> for Option<&Gd<T>> {
892887
}
893888
}
894889

890+
#[expect(deprecated)]
895891
impl<T: GodotClass> ParamType for Option<Gd<T>> {
896892
type Arg<'v> = CowArg<'v, Option<Gd<T>>>;
897893

898894
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
899895
CowArg::Owned(self)
900896
}
901-
902-
fn arg_to_ref<'r>(arg: &'r Self::Arg<'_>) -> &'r Self {
903-
arg.cow_as_ref()
904-
}
905-
906-
fn arg_into_owned(arg: Self::Arg<'_>) -> Self {
907-
arg.cow_into_owned()
908-
}
909897
}
910898

911899
impl<T> Default for Gd<T>

0 commit comments

Comments
 (0)