-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Make AsArg usable for custom functions #961
Comments
You can already declare What makes this a bit cumbersome (and the reason why As for consistent APIs, I agree that would be nice. Note that due to binding, you likely won't have 100% similarity, but we can at least strive towards it 🙂 |
Hm maybe I'm doing something wrong with the syntax. What I'm seeing is: #[godot_api]
impl CustomNode {
#[func]
pub fn test(&self, action: impl AsArg<StringName>) {}
} This throws an error on the
|
Ah yes, I thought you talked about Rust-only APIs. I assume you'd want Maybe a first step would be to forget about references and just treat things as values in |
That would be awesome if possible, but I personally don't mind a bit of boilerplate (like your current macro) inside the function definition as long as it's seamless for the caller. To me it's analogous to: fn send<S: AsRef<str>>(msg: S) {
let owned: String = msg.as_ref().into();
} Where there's some ref juggling and boilerplate for the sake of a cleaner external API. I don't think refcounting is a bad idea though. My only concern would be performance, but I'm guessing the overhead of an extra ref-count would be negligible here |
gdext 0.2 gave us the power to pass strings without
.into()
for godot APIs:Which is a really awesome feature! But when implementing custom functions that take godot string values, we still need to do:
Thinking as a plugin creator, long-term it would be valuable to allow custom node APIs to also declare their arguments using the
AsArg
trait so that users of plugins do not experience inconsistent apis (IE why do I only have to callinto()
for strings sometimes?)Not sure how feasible this actually is, but I wanted to float the idea just in case.
The text was updated successfully, but these errors were encountered: