@@ -15,11 +15,12 @@ use godot_cell::panicking::{InaccessibleGuard, MutGuard, RefGuard};
15
15
use godot_ffi:: out;
16
16
17
17
use crate :: obj:: script:: ScriptInstance ;
18
- use crate :: obj:: { AsDyn , Gd , GodotClass } ;
18
+ use crate :: obj:: { AsDyn , Gd , GodotClass , PassiveGd } ;
19
19
20
20
/// Immutably/shared bound reference guard for a [`Gd`][crate::obj::Gd] smart pointer.
21
21
///
22
22
/// See [`Gd::bind`][crate::obj::Gd::bind] for usage.
23
+ // GdRef could technically implement Clone, but it wasn't needed so far.
23
24
#[ derive( Debug ) ]
24
25
pub struct GdRef < ' a , T : GodotClass > {
25
26
guard : RefGuard < ' a , T > ,
@@ -45,8 +46,6 @@ impl<T: GodotClass> Drop for GdRef<'_, T> {
45
46
}
46
47
}
47
48
48
- // TODO Clone or Share
49
-
50
49
// ----------------------------------------------------------------------------------------------------------------------------------------------
51
50
52
51
/// Mutably/exclusively bound reference guard for a [`Gd`][crate::obj::Gd] smart pointer.
@@ -199,32 +198,24 @@ macro_rules! make_base_ref {
199
198
#[ doc = concat!( "This can be used to call methods on the base object of a " , $object_name, " that takes `&self` as the receiver.\n \n " ) ]
200
199
#[ doc = concat!( "See [`" , stringify!( $doc_type) , "::base()`](" , stringify!( $doc_path) , "::base()) for usage." ) ]
201
200
pub struct $ident<' a, T : $bound> {
202
- // Weak reference to the base object. Safe because 'a lifetime keeps the object (strong ref) alive.
203
- // Option because Gd::drop_weak() takes ownership, thus can't use ManuallyDrop.
204
- weak_gd: Option <Gd <T :: Base >>,
201
+ passive_gd: PassiveGd <' a, T :: Base >,
205
202
_instance: & ' a T ,
206
203
}
207
204
208
205
impl <' a, T : $bound> $ident<' a, T > {
209
- pub ( crate ) fn new( weak_gd : Gd < T :: Base >, instance: & ' a T ) -> Self {
206
+ pub ( crate ) fn new( passive_gd : PassiveGd < ' a , T :: Base >, instance: & ' a T ) -> Self {
210
207
Self {
211
- weak_gd : Some ( weak_gd ) ,
208
+ passive_gd ,
212
209
_instance: instance,
213
210
}
214
211
}
215
212
}
216
213
217
- impl <' a, T : $bound> Drop for $ident<' a, T > {
218
- fn drop( & mut self ) {
219
- self . weak_gd. take( ) . unwrap( ) . drop_weak( ) ;
220
- }
221
- }
222
-
223
214
impl <T : $bound> Deref for $ident<' _, T > {
224
215
type Target = Gd <T :: Base >;
225
216
226
217
fn deref( & self ) -> & Gd <T :: Base > {
227
- self . weak_gd . as_ref ( ) . unwrap ( )
218
+ & self . passive_gd
228
219
}
229
220
}
230
221
} ;
@@ -240,41 +231,33 @@ macro_rules! make_base_mut {
240
231
///
241
232
#[ doc = concat!( "See [`" , stringify!( $doc_type) , "::base_mut()`](" , stringify!( $doc_path) , "::base_mut()) for usage.\n " ) ]
242
233
pub struct $ident<' a, T : $bound> {
243
- // Weak reference to the base object. Safe because 'a lifetime keeps the object (strong ref) alive.
244
- // Option because Gd::drop_weak() takes ownership, thus can't use ManuallyDrop.
245
- weak_gd: Option <Gd <T :: Base >>,
234
+ passive_gd: PassiveGd <' a, T :: Base >,
246
235
_inaccessible_guard: InaccessibleGuard <' a, T >,
247
236
}
248
237
249
238
impl <' a, T : $bound> $ident<' a, T > {
250
239
pub ( crate ) fn new(
251
- weak_gd : Gd < T :: Base >,
240
+ passive_gd : PassiveGd < ' a , T :: Base >,
252
241
inaccessible_guard: InaccessibleGuard <' a, T >,
253
242
) -> Self {
254
243
Self {
255
- weak_gd : Some ( weak_gd ) ,
244
+ passive_gd ,
256
245
_inaccessible_guard: inaccessible_guard,
257
246
}
258
247
}
259
248
}
260
249
261
- impl <' a, T : $bound> Drop for $ident<' a, T > {
262
- fn drop( & mut self ) {
263
- self . weak_gd. take( ) . unwrap( ) . drop_weak( ) ;
264
- }
265
- }
266
-
267
250
impl <T : $bound> Deref for $ident<' _, T > {
268
251
type Target = Gd <T :: Base >;
269
252
270
253
fn deref( & self ) -> & Gd <T :: Base > {
271
- self . weak_gd . as_ref ( ) . unwrap ( )
254
+ & self . passive_gd
272
255
}
273
256
}
274
257
275
258
impl <T : $bound> DerefMut for $ident<' _, T > {
276
259
fn deref_mut( & mut self ) -> & mut Gd <T :: Base > {
277
- self . weak_gd . as_mut ( ) . unwrap ( )
260
+ & mut self . passive_gd
278
261
}
279
262
}
280
263
} ;
0 commit comments