-
-
Notifications
You must be signed in to change notification settings - Fork 242
Implement Gd::try_dynify
.
#1255
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
Conversation
e26700f
to
7c45e5e
Compare
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1255 |
7c45e5e
to
c2ecacc
Compare
bac8697
to
f72710a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
So, try_xy()
should always have the same semantics as xy()
but returning Result
/Option
instead of panic. Since into_dyn
is already taken, we need a different name.
Maybe try_dynify
? Ideally a comment in docs would explain the relation + difference between the two.
godot-core/src/obj/gd.rs
Outdated
@@ -512,6 +513,21 @@ impl<T: GodotClass> Gd<T> { | |||
DynGd::<T, D>::from_gd(self) | |||
} | |||
|
|||
/// Tries to upgrade to a `DynGd<T, D>` pointer, enabling the `D` abstraction. | |||
/// | |||
/// If `T`'s class' dynamic type doesn't implement `AsDyn<D>`, `Err(self)` is returned, meaning you can reuse the original |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"T's class' dynamic type" is a bit imprecise, since T
is a compile-time type (given by the generic parameter). You probably mean the dynamic type of self
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the "original" class 🤔 – maybe "T
's dynamic class"?
f72710a
to
0a500a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! 🙂
Adds
Gd::try_dynify
, available for engine classes (currently we can validate if user-defined class implementsAsDyn<D>
on compile time, thus makingtry_dynify
pointless – just useinto_dyn
instead).