Skip to content

Commit 712e166

Browse files
authored
Merge pull request #847 from godot-rust/qol/object-arg-mut-refs
`AsObjectArg<T>` is now implemented for `&mut Gd<T>`
2 parents b294625 + 4a1b88a commit 712e166

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

godot-core/src/obj/object_arg.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ where
6767
}
6868
}
6969

70+
impl<T, U> AsObjectArg<T> for &mut Gd<U>
71+
where
72+
T: GodotClass + Bounds<Declarer = bounds::DeclEngine>,
73+
U: Inherits<T>,
74+
{
75+
// Delegate to &Gd impl.
76+
77+
fn as_object_arg(&self) -> ObjectArg<T> {
78+
<&Gd<U>>::as_object_arg(&&**self)
79+
}
80+
81+
fn consume_object(self) -> ObjectCow<T> {
82+
<&Gd<U>>::consume_object(&*self)
83+
}
84+
}
85+
7086
impl<T, U> AsObjectArg<T> for Option<U>
7187
where
7288
T: GodotClass + Bounds<Declarer = bounds::DeclEngine>,

itest/rust/src/object_tests/object_arg_test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ fn object_arg_borrowed() {
3333
});
3434
}
3535

36+
#[itest]
37+
fn object_arg_borrowed_mut() {
38+
with_objects(|mut manual, mut refc| {
39+
let db = ClassDb::singleton();
40+
let a = db.class_set_property(&mut manual, "name".into(), Variant::from("hello"));
41+
let b = db.class_set_property(&mut refc, "value".into(), Variant::from(-123));
42+
(a, b)
43+
});
44+
}
45+
3646
#[itest]
3747
fn object_arg_option_owned() {
3848
with_objects(|manual, refc| {
@@ -53,6 +63,16 @@ fn object_arg_option_borrowed() {
5363
});
5464
}
5565

66+
#[itest]
67+
fn object_arg_option_borrowed_mut() {
68+
with_objects(|mut manual, mut refc| {
69+
let db = ClassDb::singleton();
70+
let a = db.class_set_property(Some(&mut manual), "name".into(), Variant::from("hello"));
71+
let b = db.class_set_property(Some(&mut refc), "value".into(), Variant::from(-123));
72+
(a, b)
73+
});
74+
}
75+
5676
#[itest]
5777
fn object_arg_option_none() {
5878
let manual: Option<Gd<Node>> = None;

0 commit comments

Comments
 (0)