@@ -21,27 +21,23 @@ use crate::{obj, sys};
21
21
/// without cloning. It supports nullable object passing for optional object arguments.
22
22
#[ derive( Debug , PartialEq ) ]
23
23
#[ doc( hidden) ]
24
- pub struct ObjectArg {
24
+ pub struct ObjectArg < ' gd > {
25
25
// Never dropped since it's just a view; see constructor.
26
26
object_ptr : sys:: GDExtensionObjectPtr ,
27
+ _lifetime : std:: marker:: PhantomData < & ' gd ( ) > ,
27
28
}
28
29
29
- impl ObjectArg {
30
- /// Creates `ObjectArg` from a `Gd`.
31
- ///
32
- /// # Safety
33
- /// The referenced `Gd` must remain valid for the lifetime of this `ObjectArg`.
34
- pub unsafe fn from_gd < T : GodotClass > ( obj : & Gd < T > ) -> Self {
30
+ impl < ' gd > ObjectArg < ' gd > {
31
+ /// Creates a temporary `ObjectArg` from a `Gd` reference.
32
+ pub fn from_gd < T : GodotClass > ( obj : & ' gd Gd < T > ) -> Self {
35
33
Self {
36
34
object_ptr : obj. obj_sys ( ) ,
35
+ _lifetime : std:: marker:: PhantomData ,
37
36
}
38
37
}
39
38
40
- /// Creates `ObjectArg` from an `Option<Gd>`.
41
- ///
42
- /// # Safety
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 {
39
+ /// Creates a temporary `ObjectArg` from an `Option<&Gd>` reference.
40
+ pub fn from_option_gd < T : GodotClass > ( obj : Option < & ' gd Gd < T > > ) -> Self {
45
41
match obj {
46
42
Some ( gd) => Self :: from_gd ( gd) ,
47
43
None => Self :: null ( ) ,
@@ -52,6 +48,7 @@ impl ObjectArg {
52
48
pub fn null ( ) -> Self {
53
49
Self {
54
50
object_ptr : ptr:: null_mut ( ) ,
51
+ _lifetime : std:: marker:: PhantomData ,
55
52
}
56
53
}
57
54
@@ -67,16 +64,17 @@ impl ObjectArg {
67
64
}
68
65
69
66
// #[derive(Clone)] doesn't seem to get bounds right.
70
- impl Clone for ObjectArg {
67
+ impl < ' gd > Clone for ObjectArg < ' gd > {
71
68
fn clone ( & self ) -> Self {
72
69
Self {
73
70
object_ptr : self . object_ptr ,
71
+ _lifetime : std:: marker:: PhantomData ,
74
72
}
75
73
}
76
74
}
77
75
78
76
// SAFETY: see impl GodotFfi for RawGd.
79
- unsafe impl GodotFfi for ObjectArg {
77
+ unsafe impl < ' gd > GodotFfi for ObjectArg < ' gd > {
80
78
// If anything changes here, keep in sync with RawGd impl.
81
79
82
80
const VARIANT_TYPE : ExtVariantType = ExtVariantType :: Concrete ( sys:: VariantType :: OBJECT ) ;
@@ -117,7 +115,7 @@ unsafe impl GodotFfi for ObjectArg {
117
115
}
118
116
}
119
117
120
- impl GodotFfiVariant for ObjectArg {
118
+ impl < ' gd > GodotFfiVariant for ObjectArg < ' gd > {
121
119
fn ffi_to_variant ( & self ) -> Variant {
122
120
obj:: object_ffi_to_variant ( self )
123
121
}
@@ -127,7 +125,7 @@ impl GodotFfiVariant for ObjectArg {
127
125
}
128
126
}
129
127
130
- impl GodotNullableFfi for ObjectArg {
128
+ impl < ' gd > GodotNullableFfi for ObjectArg < ' gd > {
131
129
fn null ( ) -> Self {
132
130
Self :: null ( )
133
131
}
0 commit comments