-
Notifications
You must be signed in to change notification settings - Fork 42
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
Deciding between &T
and TRef<T>
#56
Comments
Thanks for input! I think there's merit to adding information in the Ref, TRef, and Instance section of the book. Would you like to take point on a PR for mentioning this? |
If you mean if I could contribute anything: I guess I'm still struggling too much with some fundamental questions like:
Especially the latter needs to be checked first from the bindings perspective. CC @Bromeon As as side note, answering (2) is often a bit tricky, presumably due to the auto-generated nature of the bindings. For instance when searching the docs for |
In practice, it's mostly that and You can imagine a
A lot of this functionality is part of pub struct TRef<'a, T: GodotObject, Own: Ownership = Shared> {
obj: &'a T,
_marker: PhantomData<Own>,
} However, it contains other information, namely the generic type parameter So no, we cannot safely implement This being said, a lot of these things are currently in the process of being re-thought, see godot-rust/gdnative#808 for example. So while we can give recommendation on when to use Generally, with |
Thanks for the clarifications! In this case it might be best to wait a bit and see how things evolve. |
In general godot-rust allows to use e.g. either
owner: &Node
orowner: TRef<Node>
on exported methods, as noted in the Class registration section:Unless I have missed something, the book doesn't go into details why one would chose one over the other. In practice this means that most developers go for
&T
because it's simpler. This is probably the reason why many people run into problems when trying to set up signals, in particular because this example suggest that passingowner
should just work. Searching the discord history shows many cases of failed attempts to get signal connection to work, becauseowner.connect
takes atarget: AsArg
which only works withowner: TRef<T>
but not withowner: &T
(unless falling back tounsafe { owner.assume_shared() }
). I'm not sure if this limitation is by design or can perhaps be avoided eventually (c.f. godot-rust/gdnative#749). So far this is the only difference I'm aware of, but there may be further differences. Regarding the book I'd suggest:AsArg
limitation is the only difference, it would make sense to recommend usingTRef<T>
because it can do strictly more than&T
.The text was updated successfully, but these errors were encountered: