Skip to content

Commit bf402a3

Browse files
committed
Callable::from_object_method() now accepts Gd parameter by shared-ref
1 parent a971839 commit bf402a3

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

examples/dodge-the-creeps/rust/src/main_scene.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ impl Main {
105105
mob.set_linear_velocity(lin_vel);
106106

107107
let mut hud = self.base.get_node_as::<Hud>("Hud");
108-
hud.connect(
109-
"start_game".into(),
110-
Callable::from_object_method(mob, "on_start_game"),
111-
);
108+
hud.connect("start_game".into(), mob.callable("on_start_game"));
112109
}
113110

114111
fn music(&mut self) -> &mut AudioStreamPlayer {

godot-core/src/builtin/callable.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ impl Callable {
3535

3636
/// Create a callable for the method `object::method_name`.
3737
///
38+
/// See also [`Gd::callable()`].
39+
///
3840
/// _Godot equivalent: `Callable(Object object, StringName method)`_
39-
pub fn from_object_method<T, S>(object: Gd<T>, method_name: S) -> Self
41+
pub fn from_object_method<T, S>(object: &Gd<T>, method_name: S) -> Self
4042
where
4143
T: GodotClass, // + Inherits<Object>,
4244
S: Into<StringName>,

godot-core/src/obj/gd.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,12 @@ impl<T: GodotClass> Gd<T> {
385385
pub(crate) fn obj_sys(&self) -> sys::GDExtensionObjectPtr {
386386
self.raw.obj_sys()
387387
}
388+
388389
/// Returns a callable referencing a method from this object named `method_name`.
390+
///
391+
/// This is shorter syntax for [`Callable::from_object_method(self, method_name)`][Callable::from_object_method].
389392
pub fn callable<S: Into<StringName>>(&self, method_name: S) -> Callable {
390-
Callable::from_object_method(self.clone(), method_name)
393+
Callable::from_object_method(self, method_name)
391394
}
392395
}
393396

itest/rust/src/builtin_tests/containers/callable_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn callable_call_return() {
110110
#[itest]
111111
fn callable_call_engine() {
112112
let obj = Node2D::new_alloc();
113-
let cb = Callable::from_object_method(obj.clone(), "set_position");
113+
let cb = Callable::from_object_method(&obj, "set_position");
114114
let inner: InnerCallable = cb.as_inner();
115115

116116
assert!(!inner.is_null());

0 commit comments

Comments
 (0)