Closed
Description
In my project, I had a code example where I did this:
class RGlobal -> rustFunc() -> godotLoadEntity() -> use something from RGlobal
This leads to an ownership error with RGlobal.
Then I started moving the logic into Rust and got:
class RGlobal -> rustFunc() -> rustLoadEntity() -> use something from RGlobal
In the following variations, it still resulted in the same error:
fn loadEntity(&mut selfl) -> ()
{
let global: &mut Gd<RGlobal> = &mut RGlobal::getGlobal(self.base().to_godot().upcast());
let globalBind: GdMut<RGlobal> = global.bind_mut(); // <-- error
fn loadEntity(&mut self, mut rglobal: Gd<RGlobal>) -> ()
{
let globalBind: GdMut<RGlobal> = global.bind_mut(); // <-- error
This made me wonder why this was happening, so I decided to share it here.
I'll say that I fixed the issue in only one way. In issue #1157, there was an interesting example with:
let _lock_self = self.base_mut();
It turned out this also works in my case:
fn loadEntity(&mut self, rglobal: &mut RGlobal) -> ()
{
let rglobalBase: BaseMut<RGlobal> = rglobal.base_mut();
let mut rglobal: Gd<RGlobal> = rglobalBase.to_godot().cast();
let rglobalBind: GdMut<RGlobal> = rglobal.bind_mut(); // <-- ok