-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
#[derive(GodotClass)]
on tuple structs should fail before other macro failures
#545
Comments
Maybe support for tuple structs could just be added instead, but without any support for Alternatively, support for |
I'm not sure if tuple structs are useful in this context:
I agree that the error message for tuple structs should be improved though. Thanks for reporting! 🙂 |
Thanks for the input. Personally, I think that those concerns are related to tuple structs themselves, such that it's a choice to be made by the end user - when they're using a tuple struct, they know that they'd have to refactor later if they wanted to actually not make it a tuple struct. What's more, we can actually make tuple structs easier to work with through our existing macros. Let me explain. For one, I believe tuple structs are especially useful for the newtype pattern - you really don't want something named, you just want to wrap something (e.g. (I actually saw a use case for this in the gdext Discord: someone worked around the lack of support for tuple structs by using fields such as Another relevant argument is that we wouldn't be able to distinguish between tuple and non-tuple structs in a future Builder API, so support for tuple structs would be added anyway. Regarding the specific points:
You actually can through renaming, though, of course, it's better to use a named struct instead if you're going to have multiple exported properties and stuff. Either way, though, I believe it's valid in a newtype scenario where you just want to export the single field you have.
It's indeed a bit clumsy at the moment, but with #501 we'd just use
Sorry, I should have clarified: I meant an "opaque object" only for Godot - but we'd still have Rust-only (non-exported) fields we can mess with in the Rust side.
I believe that applies to tuple structs in general (not just in a Godot context), so that's generally a conscious choice (or, at least, it feels weird that we'd be imposing such a choice anyway). And changing a named struct's fields would also require significant refactor depending on the size of your code base anyway. Though using renaming would alleviate this for the specific use case where you have only one field and that's what you want to export (you want to keep it "unnamed" in the Rust side though). |
Fair point. But maybe we should then consider the newtype pattern in particular -- often you might want to expose the inner thing more or less transparently, maybe even saving some boilerplate code in the process. We already do such a distinction for gdext/itest/rust/src/register_tests/derive_variant_test.rs Lines 62 to 66 in 5e18af8
This doesn't extend naturally to all sorts of tuple structs. Especially if we add specific behavior for newtypes (i.e. tuple structs with a single field), it may be even more confusing if this behavior is different for those with multiple fields.
I don't think this is relevant -- the macro API will be a convenience layer on top of the programmatic API. As such it can be less powerful than the underlying one. But since it is essentially a DSL, it's good to have certain conventions, also for recognizability. In other words, I think it's OK if TLDR: it would be good to learn more about the newtype use case. Do you know any ways how the current |
If this hasn't been fixed yet then just fixing the right error message to trigger first should be a good first issue. whether we should support tuple-structs themselves can be resolved in another issue. |
Consider this snippet.
This is incorrect for two reasons. First, the
rename
key demands an identifier, but it's been given a string. Second, you cannot derive GodotClass on a tuple struct. Upon compilation, this yields only one error.Upon fixing this and recompiling, you see a new error.
Fixing this issue requires some degree of redesign and would likely invalidate the work done to solve the first error. As such, this latter error should be encountered first before any other errors in related macros.
The text was updated successfully, but these errors were encountered: