Skip to content

Commit f4ec18c

Browse files
committed
Remove ToGodot::into_godot(); Signature marshalling uses to_godot()
1 parent 2fac024 commit f4ec18c

File tree

9 files changed

+30
-51
lines changed

9 files changed

+30
-51
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,6 @@ impl<T: ArrayElement> ToGodot for Array<T> {
917917
//self.clone()
918918
}
919919

920-
fn into_godot(self) -> Self::Via {
921-
self
922-
}
923-
924920
fn to_variant(&self) -> Variant {
925921
self.ffi_to_variant()
926922
}
@@ -1052,8 +1048,9 @@ impl<T: ArrayElement> GodotType for Array<T> {
10521048
type Ffi = Self;
10531049

10541050
fn to_ffi(&self) -> Self::Ffi {
1055-
// `to_ffi` is sometimes intentionally called with an array in an invalid state.
1056-
self.clone()
1051+
// SAFETY: we may pass type-transmuted arrays to FFI (e.g. Array<T> as Array<Variant>). This would fail the regular
1052+
// type-check in clone(), so we disable it. Type invariants are upheld by the "front-end" APIs.
1053+
unsafe { self.clone_unchecked() }
10571054
}
10581055

10591056
fn into_ffi(self) -> Self::Ffi {

godot-core/src/meta/godot_convert/impls.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ where
101101
self.as_ref().map(ToGodot::to_godot)
102102
}
103103

104-
fn into_godot(self) -> Self::Via {
105-
self.map(ToGodot::into_godot)
106-
}
107-
108104
fn to_variant(&self) -> Variant {
109105
match self {
110106
Some(inner) => inner.to_variant(),

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ pub trait ToGodot: Sized + GodotConvert {
4747
/// Converts this type to the Godot type by reference, usually by cloning.
4848
fn to_godot(&self) -> Self::ToVia<'_>;
4949

50-
/// Converts this type to the Godot type.
51-
///
52-
/// This can in some cases enable minor optimizations, such as avoiding reference counting operations.
53-
fn into_godot(self) -> Self::Via {
54-
//self.to_godot()
55-
todo!()
56-
}
57-
5850
/// Converts this type to a [Variant].
5951
fn to_variant(&self) -> Variant {
6052
self.to_godot().to_ffi().ffi_to_variant()
@@ -103,8 +95,22 @@ pub trait FromGodot: Sized + GodotConvert {
10395
}
10496
}
10597

106-
pub(crate) fn into_ffi<T: ToGodot>(value: T) -> <T::Via as GodotType>::Ffi {
107-
value.into_godot().into_ffi()
98+
// pub(crate) fn into_ffi<'v, T: ToGodot >(value: T) -> <T::ToVia<'v> as GodotType>::Ffi {
99+
// let by_ref = value.to_godot();
100+
// let ffi = by_ref.to_ffi();
101+
//
102+
// ffi
103+
// }
104+
105+
pub(crate) fn into_ffi<'v, T: ToGodot>(value: &'v T) -> <T::ToVia<'v> as GodotType>::Ffi {
106+
let by_ref = value.to_godot();
107+
let ffi = by_ref.to_ffi();
108+
109+
ffi
110+
}
111+
112+
pub(crate) fn into_ffi_variant<T: ToGodot>(value: &T) -> Variant {
113+
GodotFfiVariant::ffi_to_variant(&into_ffi(value))
108114
}
109115

110116
pub(crate) fn try_from_ffi<T: FromGodot>(
@@ -128,11 +134,6 @@ macro_rules! impl_godot_as_self {
128134
fn to_godot(&self) -> Self::ToVia<'_> {
129135
self.clone()
130136
}
131-
132-
#[inline]
133-
fn into_godot(self) -> Self::Via {
134-
self
135-
}
136137
}
137138

138139
impl $crate::meta::FromGodot for $T {

godot-core/src/meta/signature.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use sys::{BuiltinMethodBind, ClassMethodBind, GodotFfi, UtilityFunctionBind};
1414

1515
use crate::builtin::Variant;
1616
use crate::meta::error::{CallError, ConvertError};
17-
use crate::meta::godot_convert::{into_ffi, try_from_ffi};
17+
use crate::meta::godot_convert::{into_ffi, into_ffi_variant, try_from_ffi};
1818
use crate::meta::*;
1919
use crate::obj::{GodotClass, InstanceId};
2020

@@ -225,7 +225,7 @@ macro_rules! impl_varcall_signature_for_tuple {
225225

226226
let explicit_args = [
227227
$(
228-
GodotFfiVariant::ffi_to_variant(&into_ffi($pn)),
228+
into_ffi_variant(&$pn),
229229
)*
230230
];
231231

@@ -270,7 +270,7 @@ macro_rules! impl_varcall_signature_for_tuple {
270270
let object_call_script_method = sys::interface_fn!(object_call_script_method);
271271
let explicit_args = [
272272
$(
273-
GodotFfiVariant::ffi_to_variant(&into_ffi($pn)),
273+
into_ffi_variant(&$pn),
274274
)*
275275
];
276276

@@ -305,7 +305,7 @@ macro_rules! impl_varcall_signature_for_tuple {
305305

306306
let explicit_args: [Variant; $PARAM_COUNT] = [
307307
$(
308-
GodotFfiVariant::ffi_to_variant(&into_ffi($pn)),
308+
into_ffi_variant(&$pn),
309309
)*
310310
];
311311

@@ -392,7 +392,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
392392
#[allow(clippy::let_unit_value)]
393393
let marshalled_args = (
394394
$(
395-
into_ffi($pn),
395+
into_ffi(&$pn),
396396
)*
397397
);
398398

@@ -423,7 +423,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
423423
#[allow(clippy::let_unit_value)]
424424
let marshalled_args = (
425425
$(
426-
into_ffi($pn),
426+
into_ffi(&$pn),
427427
)*
428428
);
429429

@@ -451,7 +451,7 @@ macro_rules! impl_ptrcall_signature_for_tuple {
451451
#[allow(clippy::let_unit_value)]
452452
let marshalled_args = (
453453
$(
454-
into_ffi($pn),
454+
into_ffi(&$pn),
455455
)*
456456
);
457457

@@ -548,7 +548,9 @@ unsafe fn ptrcall_return<R: ToGodot>(
548548
_call_ctx: &CallContext,
549549
call_type: sys::PtrcallType,
550550
) {
551-
let val = into_ffi(ret_val);
551+
//let val = into_ffi(ret_val);
552+
let val = ret_val.to_godot().to_ffi();
553+
552554
val.move_return_ptr(ret, call_type);
553555
}
554556

godot-core/src/meta/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait GodotType: GodotConvert<Via = Self> + sealed::Sealed + Sized + 'static
4242
// 'static is not technically required, but it simplifies a few things (limits e.g. ObjectArg).
4343
{
4444
#[doc(hidden)]
45-
type Ffi: GodotFfiVariant;
45+
type Ffi: GodotFfiVariant + 'static;
4646

4747
#[doc(hidden)]
4848
fn to_ffi(&self) -> Self::Ffi;

godot-core/src/obj/gd.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,6 @@ impl<T: GodotClass> ToGodot for Gd<T> {
685685
self.raw.check_rtti("to_godot");
686686
self.clone()
687687
}
688-
689-
fn into_godot(self) -> Self::Via {
690-
self.raw.check_rtti("into_godot");
691-
self
692-
}
693688
}
694689

695690
impl<T: GodotClass> FromGodot for Gd<T> {

godot-core/src/obj/object_arg.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ impl<T: GodotClass> ToGodot for ObjectArg<T> {
259259
fn to_godot(&self) -> Self::ToVia<'_> {
260260
(*self).clone()
261261
}
262-
263-
fn into_godot(self) -> Self::Via {
264-
self
265-
}
266262
}
267263

268264
// TODO refactor signature tuples into separate in+out traits, so FromGodot is no longer needed.

godot-core/src/obj/raw_gd.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,6 @@ impl<T: GodotClass> ToGodot for RawGd<T> {
541541
fn to_godot(&self) -> Self::ToVia<'_> {
542542
self.clone()
543543
}
544-
545-
fn into_godot(self) -> Self::Via {
546-
self
547-
}
548544
}
549545

550546
impl<T: GodotClass> FromGodot for RawGd<T> {

godot-macros/src/derive/derive_to_godot.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ fn make_togodot_for_newtype_struct(name: &Ident, field: &NewtypeStruct) -> Token
4848
fn to_godot(&self) -> #via_type {
4949
::godot::meta::ToGodot::to_godot(&self.#field_name)
5050
}
51-
52-
fn into_godot(self) -> #via_type {
53-
::godot::meta::ToGodot::into_godot(self.#field_name)
54-
}
5551
}
5652
}
5753
}

0 commit comments

Comments
 (0)