-
Notifications
You must be signed in to change notification settings - Fork 307
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
Conflict between keywords in Rust and Dart #2066
Comments
Totally agree! As for API, we already have Feel free to PR for this, alternatively I may work on it later!
I guess it is because v2 overhauled a lot of things... |
Looking forward to it. |
Btw, curious what was the generated output in v1 that does not have problem? (Does it auto rename, or do something else) |
I guess the direct reason is that the issued rust struct is not directly in use, so it was not generated at that time(I checked the git diff of generated dart files).
Semantically, And when I did it with frb v1(the version I modified), |
I see, then it looks like v2 does not introduce anything special compared with v1. Anyway, I am working on it. |
Looks reasonable! However, there may be some complications: If a file does not change content, it is great to ensure it is not modified (this seems not to be implemented now but may impl in the future), otherwise Rust/Dart compilation cache will fail, and users may observe slower compilation time. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue. |
Issue
For a rust struct without any impl block:
it failed to finish generation, because of the keyword
class
, some err msgs like these:column 1 of lib\src\rust\frb_generated.dart: 'class' can't be used as an identifier because it's a keyword.
line 24, column 1 of lib\src\rust\media\cms_media_outline.dart: Can't have modifier 'final' here. ╷ 24 │ final List<MediaClass> class;
, which stuck the generation dart:
Suggestion
This can be worked around by manually changing the field name. But I wonder whether it is possible to do it by generation automatically without ruining the existed rust code---For example, using a new frb macro to replace it like the serde macro
#[frb(deserialize_with = "your_dart_field_name")]
.With this feature, whenever there is a key word conflicting, there is no need for user to modify the rust part code.
Other Thoughts
Though I know the
class
is always the keyword of dart, I wonder why the same rust code could be compiled 6 months ago when it was the last time I modified the rust struct with FRB v1.Besides, I've thought of other ways to work around it, like reflection in Dart side. But it seems that there is not a way good enough for both pure Dart and Fluttter projects.
The text was updated successfully, but these errors were encountered: