Skip to content

Commit 3b3fedb

Browse files
committed
Remove blanket ToGodot/FromGodot pointer impls -> specific ones for native structs instead
1 parent 7426b7f commit 3b3fedb

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

godot-codegen/src/class_generator.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,15 +880,52 @@ fn make_native_structure(
880880

881881
let imports = util::make_imports();
882882
let fields = make_native_structure_fields(&structure.format, ctx);
883+
let doc = format!("[`ToGodot`] and [`FromGodot`] are implemented for `*mut {class_name}` and `*const {class_name}`.");
883884

884885
// mod re_export needed, because class should not appear inside the file module, and we can't re-export private struct as pub
885886
let tokens = quote! {
886887
#imports
888+
use crate::builtin::meta::{GodotConvert, FromGodot, ToGodot};
887889

890+
/// Native structure; can be passed via pointer in APIs that are not exposed to GDScript.
891+
///
892+
#[doc = #doc]
888893
#[repr(C)]
889894
pub struct #class_name {
890895
#fields
891896
}
897+
898+
impl GodotConvert for *mut #class_name {
899+
type Via = i64;
900+
}
901+
902+
impl ToGodot for *mut #class_name {
903+
fn to_godot(&self) -> Self::Via {
904+
*self as i64
905+
}
906+
}
907+
908+
impl FromGodot for *mut #class_name {
909+
fn try_from_godot(via: Self::Via) -> Option<Self> {
910+
Some(via as Self)
911+
}
912+
}
913+
914+
impl GodotConvert for *const #class_name {
915+
type Via = i64;
916+
}
917+
918+
impl ToGodot for *const #class_name {
919+
fn to_godot(&self) -> Self::Via {
920+
*self as i64
921+
}
922+
}
923+
924+
impl FromGodot for *const #class_name {
925+
fn try_from_godot(via: Self::Via) -> Option<Self> {
926+
Some(via as Self)
927+
}
928+
}
892929
};
893930
// note: TypePtr -> ObjectPtr conversion OK?
894931

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

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use crate::builtin::meta::{impl_godot_as_self, FromGodot, GodotConvert, GodotType, ToGodot};
88
use godot_ffi as sys;
99

10+
// The following ToGodot/FromGodot/Convert impls are auto-generated for each engine type, co-located with their definitions:
11+
// - enum
12+
// - const/mut pointer to native struct
13+
1014
// ----------------------------------------------------------------------------------------------------------------------------------------------
1115
// Option
1216

@@ -89,41 +93,6 @@ impl FromGodot for sys::VariantOperator {
8993
}
9094
}
9195

92-
// ----------------------------------------------------------------------------------------------------------------------------------------------
93-
// Pointers
94-
95-
impl<T> GodotConvert for *mut T {
96-
type Via = i64;
97-
}
98-
99-
impl<T> ToGodot for *mut T {
100-
fn to_godot(&self) -> Self::Via {
101-
*self as i64
102-
}
103-
}
104-
105-
impl<T> FromGodot for *mut T {
106-
fn try_from_godot(via: Self::Via) -> Option<Self> {
107-
Some(via as Self)
108-
}
109-
}
110-
111-
impl<T> GodotConvert for *const T {
112-
type Via = i64;
113-
}
114-
115-
impl<T> ToGodot for *const T {
116-
fn to_godot(&self) -> Self::Via {
117-
*self as i64
118-
}
119-
}
120-
121-
impl<T> FromGodot for *const T {
122-
fn try_from_godot(via: Self::Via) -> Option<Self> {
123-
Some(via as Self)
124-
}
125-
}
126-
12796
// ----------------------------------------------------------------------------------------------------------------------------------------------
12897
// Scalars
12998

0 commit comments

Comments
 (0)