-
Notifications
You must be signed in to change notification settings - Fork 382
Generic enums with concrete type aliases #2933
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
base: master
Are you sure you want to change the base?
Generic enums with concrete type aliases #2933
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2933 +/- ##
==========================================
- Coverage 98.57% 1.83% -96.75%
==========================================
Files 464 363 -101
Lines 19202 14525 -4677
==========================================
- Hits 18928 266 -18662
- Misses 274 14259 +13985 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Great job! Feel free to ping me if need any suggestions |
266e522 to
53faf68
Compare
1dca824 to
7923a8e
Compare
7923a8e to
b2f8b1e
Compare
|
@fzyzcjy I've made a few more fixes and it works reliably now for my use case. |
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.
Pull request overview
This PR implements support for generic enums with concrete type aliases in flutter_rust_bridge, enabling developers to define a generic enum template and instantiate it with specific types through type aliases. The feature allows both visible generic enums (e.g., ChangeTwinNormal<T>) and ignored generic enum templates (e.g., ChangeIgnoredTwinNormal<T> with #[frb(ignore)]) that can be instantiated via #[frb(non_opaque)] type aliases.
Key Changes:
- Added generic enum support with type alias instantiation across multiple test variants (Normal, Sync, SSE, RustAsync, RustAsyncSSE)
- Generated comprehensive Dart code for enum variants with freezed classes
- Added test cases covering identity functions, nested generics in StreamSink, and struct wrappers
- Updated dependency versions in pubspec.lock files
Reviewed changes
Copilot reviewed 83 out of 96 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
frb_example/pure_dart/rust/src/api/enumeration.rs |
Implements generic enum ChangeTwinNormal<T> with String and HashMap type aliases, plus ignored template pattern with ChangeIgnoredTwinNormal<T> |
frb_example/pure_dart/rust/src/api/pseudo_manual/enumeration_twin_*.rs |
Adds ChangeTwin*<T> generic enums with String type aliases across all test variants (Sync, SSE, RustAsync, RustAsyncSSE) |
frb_example/pure_dart/test/api/enumeration_test.dart |
Adds comprehensive tests for generic enum functionality including identity functions, nested generics in StreamSink, and batch/struct wrappers |
frb_example/pure_dart/lib/src/rust/api/enumeration.dart |
Generated Dart API with freezed classes for all concrete enum instantiations (ChangeStringTwinNormal, ChangeMapTwinNormal, etc.) |
frb_example/pure_dart/rust/src/frb_generated.rs |
Generated bridge code with codec implementations, wire functions, and type conversions for the new generic enum types |
tools/frb_internal/pubspec.lock, frb_example/rust_ui_*/pubspec.lock |
Updated Dart SDK and package dependencies |
frb_example/dart_minimal/rust/src/frb_generated.rs |
Removed clippy::uninlined_format_args lint suppression |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fzyzcjy
left a comment
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.
Excellent job!
| arg | ||
| } | ||
|
|
||
| pub struct Batch<T> { |
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.
BatchTwinNormal?
| } | ||
|
|
||
| #[frb(non_opaque)] | ||
| pub struct Butch<T> { |
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.
maybe AnotherBatchTwiNormal
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.
Before digging into details, I wonder whether it will generalize to generic structs (seems you add some fields to struct logic, but there are no tests yet)
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.
Thinking of investigating this myself. This would be really useful
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.
Totally agree!
b2f8b1e to
ee99ac3
Compare
Changes
Fixes #2252
The idea of this PR is to be able to do something like this:
Procedure and Checklist
In order to quickly iterate and avoid slowing down development pace by making CI pass, only the following simplified steps are needed, and I (fzyzcjy) will handle the rest of CI / moving the tests currently (will have more automation in the future).
frb_example/dart_minimal.dart_minimal's CI green.Utility commands
cargo run --manifest-path /path/to/flutter_rust_bridge/frb_codegen/Cargo.toml -- generate./frb_internal test-dart-native --package frb_example/dart_minimal