Skip to content

Commit 9e4f380

Browse files
authored
Merge pull request #943 from godot-rust/qol/arg-and-3d
Remove `to_2d()` + `to_3d()`; clean up `ApiParam`
2 parents 3722014 + 3aefb03 commit 9e4f380

File tree

9 files changed

+20
-34
lines changed

9 files changed

+20
-34
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ impl<'r, T: ArrayElement> AsArg<Array<T>> for &'r Array<T> {
947947
impl<T: ArrayElement> ApiParam for Array<T> {
948948
type Arg<'v> = CowArg<'v, Self>;
949949

950-
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
950+
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
951951
CowArg::Owned(self)
952952
}
953953

@@ -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(ApiParam::value_to_arg(item));
1224+
self.push(ApiParam::owned_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::ApiParam::value_to_arg(item));
494+
self.push(meta::ApiParam::owned_to_arg(item));
495495
}
496496
}
497497
}

godot-core/src/builtin/vectors/vector2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use sys::{ffi_methods, GodotFfi};
1111

1212
use crate::builtin::math::{FloatExt, GlamConv, GlamType};
1313
use crate::builtin::vectors::Vector2Axis;
14-
use crate::builtin::{inner, real, RAffine2, RVec2, Vector2i, Vector3};
14+
use crate::builtin::{inner, real, RAffine2, RVec2, Vector2i};
1515

1616
use std::fmt;
1717

@@ -44,7 +44,7 @@ use std::fmt;
4444
/// | 3D | [`Vector3`][crate::builtin::Vector3] | [`Vector3i`][crate::builtin::Vector3i] |
4545
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
4646
///
47-
/// <br>You can convert to 3D vectors using [`to_3d(z)`][Self::to_3d], and to `Vector2i` using [`cast_int()`][Self::cast_int].
47+
/// <br>You can convert to `Vector2i` using [`cast_int()`][Self::cast_int].
4848
///
4949
/// # Godot docs
5050
///

godot-core/src/builtin/vectors/vector2i.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::cmp::Ordering;
1010
use sys::{ffi_methods, GodotFfi};
1111

1212
use crate::builtin::math::{GlamConv, GlamType};
13-
use crate::builtin::{inner, real, RVec2, Vector2, Vector2Axis, Vector3i};
13+
use crate::builtin::{inner, real, RVec2, Vector2, Vector2Axis};
1414

1515
use std::fmt;
1616

@@ -42,7 +42,7 @@ use std::fmt;
4242
/// | 3D | [`Vector3`][crate::builtin::Vector3] | [`Vector3i`][crate::builtin::Vector3i] |
4343
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
4444
///
45-
/// <br>You can convert to 3D vectors using [`to_3d(z)`][Self::to_3d], and to `Vector2` using [`cast_float()`][Self::cast_float].
45+
/// <br>You can convert to `Vector2` using [`cast_float()`][Self::cast_float].
4646
///
4747
/// # Godot docs
4848
///

godot-core/src/builtin/vectors/vector3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use std::fmt;
4545
/// | 3D | **`Vector3`** | [`Vector3i`][crate::builtin::Vector3i] |
4646
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
4747
///
48-
/// <br>You can convert to 2D vectors using [`to_2d()`][Self::to_2d], and to `Vector3i` using [`cast_int()`][Self::cast_int].
48+
/// <br>You can convert to `Vector3i` using [`cast_int()`][Self::cast_int].
4949
///
5050
/// # Godot docs
5151
///

godot-core/src/builtin/vectors/vector3i.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use godot_ffi as sys;
1212
use sys::{ffi_methods, GodotFfi};
1313

1414
use crate::builtin::math::{GlamConv, GlamType};
15-
use crate::builtin::{inner, real, RVec3, Vector2i, Vector3, Vector3Axis};
15+
use crate::builtin::{inner, real, RVec3, Vector3, Vector3Axis};
1616

1717
/// Vector used for 3D math using integer coordinates.
1818
///
@@ -42,7 +42,7 @@ use crate::builtin::{inner, real, RVec3, Vector2i, Vector3, Vector3Axis};
4242
/// | 3D | [`Vector3`][crate::builtin::Vector3] | **`Vector3i`** |
4343
/// | 4D | [`Vector4`][crate::builtin::Vector4] | [`Vector4i`][crate::builtin::Vector4i] |
4444
///
45-
/// <br>You can convert to 2D vectors using [`to_2d()`][Self::to_2d], and to `Vector3` using [`cast_float()`][Self::cast_float].
45+
/// <br>You can convert to `Vector3` using [`cast_float()`][Self::cast_float].
4646
///
4747
/// # Godot docs
4848
///

godot-core/src/builtin/vectors/vector_macros.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,6 @@ macro_rules! impl_vector2x_fns {
791791
/// # 2D functions
792792
/// The following methods are only available on 2D vectors (for both float and int).
793793
impl $Vector {
794-
/// Increases dimension to 3D, accepting a new value for the Z component.
795-
#[inline]
796-
pub fn to_3d(self, z: $Scalar) -> $Vector3D {
797-
<$Vector3D>::new(self.x, self.y, z)
798-
}
799-
800794
/// Returns the aspect ratio of this vector, the ratio of [`Self::x`] to [`Self::y`].
801795
#[inline]
802796
pub fn aspect(self) -> real {
@@ -853,15 +847,6 @@ macro_rules! impl_vector3x_fns {
853847
/// # 3D functions
854848
/// The following methods are only available on 3D vectors (for both float and int).
855849
impl $Vector {
856-
/// Reduces dimension to 2D, discarding the Z component.
857-
///
858-
/// See also [`swizzle!`][crate::builtin::swizzle] for a more general way to extract components.
859-
/// `self.to_2d()` is equivalent to `swizzle!(self => x, y)`.
860-
#[inline]
861-
pub fn to_2d(self) -> $Vector2D {
862-
<$Vector2D>::new(self.x, self.y)
863-
}
864-
865850
/// Returns the axis of the vector's highest value. See [`Vector3Axis`] enum. If all components are equal, this method returns [`None`].
866851
///
867852
/// To mimic Godot's behavior, unwrap this function's result with `unwrap_or(Vector3Axis::X)`.

godot-core/src/meta/as_arg.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 [`ApiParam::value_to_arg()`].
26+
/// If you need to pass owned values in generic code, you can use [`ApiParam::owned_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
@@ -106,7 +106,7 @@ macro_rules! impl_asarg_by_value {
106106
impl $crate::meta::ApiParam for $T {
107107
type Arg<'v> = $T;
108108

109-
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
109+
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
110110
self
111111
}
112112

@@ -139,7 +139,7 @@ macro_rules! impl_asarg_by_ref {
139139
impl $crate::meta::ApiParam for $T {
140140
type Arg<'v> = $crate::meta::CowArg<'v, $T>;
141141

142-
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
142+
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
143143
$crate::meta::CowArg::Owned(self)
144144
}
145145

@@ -252,22 +252,23 @@ impl AsArg<NodePath> for &String {
252252
/// Implemented for all parameter types `T` that are allowed to receive [impl `AsArg<T>`][AsArg].
253253
pub trait ApiParam: GodotType
254254
// GodotType bound not required right now, but conceptually should always be the case.
255-
where
256-
Self: Sized,
257255
{
258256
/// Canonical argument passing type, either `T` or an internally-used CoW type.
259257
///
260258
/// The general rule is that `Copy` types are passed by value, while the rest is passed by reference.
261259
///
262-
/// This associated type is closely related to [`ToGodot::ToVia<'v>`][crate::meta::ToGodot::ToVia] and may be reorganized.
260+
/// This associated type is closely related to [`ToGodot::ToVia<'v>`][crate::meta::ToGodot::ToVia] and may be reorganized in the future.
261+
#[doc(hidden)]
263262
type Arg<'v>: AsArg<Self>
264263
where
265264
Self: 'v;
266265

267266
/// Converts an owned value to the canonical argument type, which can be passed to [`impl AsArg<T>`][AsArg].
268267
///
269268
/// Useful in generic contexts where only a value is available, and one doesn't want to dispatch between value/reference.
270-
fn value_to_arg<'v>(self) -> Self::Arg<'v>;
269+
///
270+
/// You should not rely on the exact return type, as it may change in future versions; treat it like `impl AsArg<Self>`.
271+
fn owned_to_arg<'v>(self) -> Self::Arg<'v>;
271272

272273
/// Converts an argument to a shared reference.
273274
///

godot-core/src/obj/gd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<'r, T: GodotClass> AsArg<Gd<T>> for &'r Gd<T> {
784784
impl<T: GodotClass> ApiParam for Gd<T> {
785785
type Arg<'v> = CowArg<'v, Gd<T>>;
786786

787-
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
787+
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
788788
CowArg::Owned(self)
789789
}
790790

@@ -806,7 +806,7 @@ impl<'r, T: GodotClass> AsArg<Option<Gd<T>>> for Option<&'r Gd<T>> {
806806
impl<T: GodotClass> ApiParam for Option<Gd<T>> {
807807
type Arg<'v> = CowArg<'v, Option<Gd<T>>>;
808808

809-
fn value_to_arg<'v>(self) -> Self::Arg<'v> {
809+
fn owned_to_arg<'v>(self) -> Self::Arg<'v> {
810810
CowArg::Owned(self)
811811
}
812812

0 commit comments

Comments
 (0)