-
-
Notifications
You must be signed in to change notification settings - Fork 224
Gd
for user objects: should self
have Deref/DerefMut
?
#131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Cool! Also, as another motivation, I have at least one case where I want my own custom |
Can you tell us more about that use case? Would that even work with the orphan rule? |
Sorry, this is for my own custom type that has fields that I want a |
But that could fail if |
Hmm, I may be missing something here, but the Maybe it is indicative of poor design on the user side, but in my code it would turn this:
into this:
|
Ah makes sense -- you have |
At the moment,
#[derive(GodotClass)]
provides aDeref
andDerefMut
impl on the user-defined struct, with the target type being the immediate base class.Inside inherent methods, this allows direct access to base functionality:
and outside:
So it makes access a bit shorter. However, it also has downsides:
self.base.method()
andself.method()
.(this happened already)
Object
andNode
tend to have very generic names such ascall
,set
,to_string
, etc. But also things likeset_position
tend to be quite common in gamedev-related types.bind
/bind_mut
guards, even though this is should not be necessary.Or should it?
call("method", args)
). This must however still go through the internalRefCell
, as we need to get the receiver&self
/&mut self
from somewhere.upcast()
.If we remove
impl Deref/DerefMut
onself
types, we could:self.base
whenever a base method is needed.Gd::base()
,Gd::upcast_direct()
,Gd::upcast_one()
or so that provides the immediate base class.Then, people could simply replace
obj.bind().method()
withobj.base().method()
.In addition to this, we might consider if
Gd<T>
should be retrievable from&self
/&mut self
. This is already possible via workarounds. For example, store anOption<Gd<T>>
inside the user object as a self-referential, late-init pointer, which is written from the outside:Or much simpler:
self.base.cast::<Self>()
.Ideally we have some concrete use cases.
self.connect()
was mentioned, but that takes a base object, not a user one.The text was updated successfully, but these errors were encountered: