@@ -93,7 +93,6 @@ fn make_native_structure(
9393 let tokens = quote ! {
9494 #imports
9595 use std:: ffi:: c_void; // for opaque object pointer fields
96- use crate :: meta:: { GodotConvert , EngineFromGodot , EngineToGodot } ;
9796
9897 /// Native structure; can be passed via pointer in APIs that are not exposed to GDScript.
9998 ///
@@ -107,58 +106,7 @@ fn make_native_structure(
107106 #methods
108107 }
109108
110- impl GodotConvert for * mut #class_name {
111- type Via = i64 ;
112- }
113-
114- // Native structure pointers implement internal-only conversion traits for use in engine APIs.
115- impl EngineToGodot for * mut #class_name {
116- type Pass = crate :: meta:: ByValue ;
117-
118- fn engine_to_godot( & self ) -> crate :: meta:: ToArg <' _, Self :: Via , Self :: Pass > {
119- * self as i64
120- }
121-
122- fn engine_to_variant( & self ) -> crate :: builtin:: Variant {
123- crate :: builtin:: Variant :: from( * self as i64 )
124- }
125- }
126-
127- impl EngineFromGodot for * mut #class_name {
128- fn engine_try_from_godot( via: Self :: Via ) -> Result <Self , crate :: meta:: error:: ConvertError > {
129- Ok ( via as Self )
130- }
131-
132- fn engine_try_from_variant( variant: & crate :: builtin:: Variant ) -> Result <Self , crate :: meta:: error:: ConvertError > {
133- variant. try_to:: <i64 >( ) . map( |i| i as Self )
134- }
135- }
136-
137- impl GodotConvert for * const #class_name {
138- type Via = i64 ;
139- }
140-
141- impl EngineToGodot for * const #class_name {
142- type Pass = crate :: meta:: ByValue ;
143-
144- fn engine_to_godot( & self ) -> crate :: meta:: ToArg <' _, Self :: Via , Self :: Pass > {
145- * self as i64
146- }
147-
148- fn engine_to_variant( & self ) -> crate :: builtin:: Variant {
149- crate :: builtin:: Variant :: from( * self as i64 )
150- }
151- }
152-
153- impl EngineFromGodot for * const #class_name {
154- fn engine_try_from_godot( via: Self :: Via ) -> Result <Self , crate :: meta:: error:: ConvertError > {
155- Ok ( via as Self )
156- }
157-
158- fn engine_try_from_variant( variant: & crate :: builtin:: Variant ) -> Result <Self , crate :: meta:: error:: ConvertError > {
159- variant. try_to:: <i64 >( ) . map( |i| i as Self )
160- }
161- }
109+ // Pointer conversions are now handled by RawPtr<P>, no direct ToGodot/FromGodot impls.
162110 } ;
163111 // note: TypePtr -> ObjectPtr conversion OK?
164112
@@ -233,7 +181,11 @@ fn make_native_structure_field_and_accessor(
233181 }
234182
235183 /// Sets the object from a `Gd` pointer holding `Node` or a derived class.
236- pub fn #setter_name<T >( & mut self , #snake_field_name: Gd <T >)
184+ ///
185+ /// # Safety
186+ /// You must ensure that the provided object remains alive while Godot accesses it.
187+ /// See also [`RawPtr::new()`][crate::meta::RawPtr::new].
188+ pub unsafe fn #setter_name<T >( & mut self , #snake_field_name: Gd <T >)
237189 where T : crate :: obj:: Inherits <Object > {
238190 use crate :: meta:: GodotType as _;
239191
@@ -245,7 +197,10 @@ fn make_native_structure_field_and_accessor(
245197 let id = obj. instance_id( ) . to_u64( ) ;
246198
247199 self . #id_field_name = ObjectId { id } ;
248- self . #field_name = obj. obj_sys( ) as * mut std:: ffi:: c_void;
200+
201+ // SAFETY: provided by method safety contract.
202+ // Godot declares void* but expects GDExtensionObjectPtr.
203+ self . #field_name = unsafe { RawPtr :: new( obj. obj_sys( ) . cast:: <std:: ffi:: c_void>( ) ) } ;
249204 }
250205 } ) ;
251206 } else {
0 commit comments