Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.world
godot_rustยทgodot-rustbytuto

Small API change with https://github.com/godot-rust/gdext/pull/370

From Bromeon:

"Small API change with https://github.com/godot-rust/gdext/pull/370.

There is no more implicit base in user methods, to make a clearer separation between the Rust object (self) and the Godot one (self.base).

fn method(&self) {
    // instead of:
    let pos = self.get_position();
    // now:
    let pos = self.base.get_position();
}

On the other hand, Gd now always has Deref and DerefMut, not only for Godot objects.

fn free_function() {
    let obj: Gd = ...;

    // instead of:
    let pos = obj.bind().get_position(); // or
    let pos = obj.upcast::().get_position();
    // now:
    let pos = obj.get_position();
}

I also improved some safety around the internal instance storage in the process.

In the near future, we need to observe whether the slightly more verbose self.base instead of self is a real issue in practice. However, it comes with quite a few advantages:

  • It's easier to keep the user object self and the Godot object self.base apart, when not all symbols are in one namespace.
  • It's less tempting to do gd.bind_mut().get_position().
    • Now it would be gd.bind_mut().base.get_position() -- however one can as well do gd.get_position() directly. The user is encouraged in the right direction.
  • Users can implement their own custom Deref/DerefMut on T, we don't impose an implementation.
  • We don't cause compilation errors due to orphan rule, if T lives in another crate.

So if you want to update, keep in mind that this has not yet fully settled and may see some changes again ๐Ÿ˜‰"

https://discord.com/channels/723850269347283004/954716999211180102/1136771777549308057Open linkView original on lemmy.world
5

No replies yet

No comments on the original post yet.