File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
itest/rust/src/object_tests Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -444,6 +444,23 @@ impl<T: GodotClass> Gd<T> {
444
444
} )
445
445
}
446
446
447
+ /// Runs the given Closure deferred.
448
+ ///
449
+ /// The closure receives a reference to this object back.
450
+ /// This can be a type-safe alternative to [`Object::call_deferred`], but does not handle
451
+ /// dynamic dispatch, unless explicitly used.
452
+ pub fn apply_deferred < F > ( & mut self , mut rust_function : F )
453
+ where
454
+ F : FnMut ( Gd < T > ) + ' static ,
455
+ {
456
+ let this = self . clone ( ) ;
457
+ let callable = Callable :: from_local_fn ( "apply_deferred" , move |_| {
458
+ rust_function ( this. clone ( ) ) ;
459
+ Ok ( Variant :: nil ( ) )
460
+ } ) ;
461
+ callable. call_deferred ( & [ ] ) ;
462
+ }
463
+
447
464
/// Returns `Ok(cast_obj)` on success, `Err(self)` on error.
448
465
// Visibility: used by DynGd.
449
466
pub ( crate ) fn owned_cast < U > ( self ) -> Result < Gd < U > , Self >
Original file line number Diff line number Diff line change @@ -62,9 +62,20 @@ impl INode for DeferredTestNode {
62
62
fn calls_method_names_deferred ( ctx : & crate :: framework:: TestContext ) -> TaskHandle {
63
63
let mut test_node = DeferredTestNode :: new_alloc ( ) ;
64
64
ctx. scene_tree . clone ( ) . add_child ( & test_node) ;
65
-
65
+
66
66
test_node. call_deferred ( "accept" , & [ ] ) ;
67
67
68
68
let handle = test_node. bind ( ) . as_expectation_task ( ) ;
69
69
handle
70
70
}
71
+
72
+ #[ itest( async ) ]
73
+ fn calls_closure_deferred ( ctx : & crate :: framework:: TestContext ) -> TaskHandle {
74
+ let mut test_node = DeferredTestNode :: new_alloc ( ) ;
75
+ ctx. scene_tree . clone ( ) . add_child ( & test_node) ;
76
+
77
+ test_node. apply_deferred ( |mut this| this. bind_mut ( ) . accept ( ) ) ;
78
+
79
+ let handle = test_node. bind ( ) . as_expectation_task ( ) ;
80
+ handle
81
+ }
You can’t perform that action at this time.
0 commit comments