@@ -9,7 +9,10 @@ use std::ptr;
9
9
10
10
use godot_ffi:: { ExtVariantType , GodotFfi , GodotNullableFfi , PtrcallType } ;
11
11
12
- use crate :: obj:: { Gd , GodotClass , Inherits , RawGd } ;
12
+ use crate :: builtin:: Variant ;
13
+ use crate :: meta:: error:: ConvertError ;
14
+ use crate :: meta:: traits:: GodotFfiVariant ;
15
+ use crate :: obj:: { Gd , GodotClass } ;
13
16
use crate :: { obj, sys} ;
14
17
15
18
/// View for object arguments passed to the Godot engine. Never owning; must be null or backed by `Gd<T>`.
@@ -34,29 +37,13 @@ impl ObjectArg {
34
37
}
35
38
}
36
39
37
- /// Creates `ObjectArg` from a `RawGd `.
40
+ /// Creates `ObjectArg` from an `Option<Gd> `.
38
41
///
39
42
/// # Safety
40
- /// The referenced `RawGd` must remain valid for the lifetime of this `ObjectArg`.
41
- pub unsafe fn from_raw_gd < T : GodotClass > ( obj : & RawGd < T > ) -> Self {
42
- // Runtime check is necessary, to ensure that object is still alive and has correct runtime type.
43
- if !obj. is_null ( ) {
44
- obj. check_rtti ( "from_raw_gd" ) ;
45
- }
46
-
47
- Self {
48
- object_ptr : obj. obj_sys ( ) ,
49
- }
50
- }
51
-
52
- /// Creates `ObjectArg` from `Option<&Gd<U>>`, handling upcast to target type `T`.
53
- pub fn from_option_gd_ref < T , U > ( opt : Option < & Gd < U > > ) -> Self
54
- where
55
- T : GodotClass ,
56
- U : GodotClass + Inherits < T > ,
57
- {
58
- match opt {
59
- Some ( gd) => unsafe { Self :: from_gd ( gd) } ,
43
+ /// The referenced `Gd`, if not `None`, must remain valid for the lifetime of this `ObjectArg`.
44
+ pub unsafe fn from_option_gd < T : GodotClass > ( obj : Option < & Gd < T > > ) -> Self {
45
+ match obj {
46
+ Some ( gd) => Self :: from_gd ( gd) ,
60
47
None => Self :: null ( ) ,
61
48
}
62
49
}
@@ -72,11 +59,6 @@ impl ObjectArg {
72
59
pub fn is_null ( & self ) -> bool {
73
60
self . object_ptr . is_null ( )
74
61
}
75
-
76
- /// Returns the raw object pointer
77
- pub fn raw_ptr ( & self ) -> sys:: GDExtensionObjectPtr {
78
- self . object_ptr
79
- }
80
62
}
81
63
82
64
// #[derive(Clone)] doesn't seem to get bounds right.
@@ -130,6 +112,16 @@ unsafe impl GodotFfi for ObjectArg {
130
112
}
131
113
}
132
114
115
+ impl GodotFfiVariant for ObjectArg {
116
+ fn ffi_to_variant ( & self ) -> Variant {
117
+ obj:: object_ffi_to_variant ( self )
118
+ }
119
+
120
+ fn ffi_from_variant ( _variant : & Variant ) -> Result < Self , ConvertError > {
121
+ unreachable ! ( "ObjectArg should only be passed *to* Godot, not *from*." )
122
+ }
123
+ }
124
+
133
125
impl GodotNullableFfi for ObjectArg {
134
126
fn null ( ) -> Self {
135
127
Self :: null ( )
0 commit comments