Skip to content

Conversation

@nightscape
Copy link

@nightscape nightscape commented Nov 21, 2025

Changes

Fixes #2252

The idea of this PR is to be able to do something like this:

pub enum Change<T> {
    Created { data: T },
    Updated { id: String, data: T },
    Deleted { id: String },
}

pub type StringChange = Change<String>;
pub type MapChange = Change<HashMap<String, String>>;

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).

  • Implement the feature / fix the bug.
  • Add tests in frb_example/dart_minimal.
  • Make dart_minimal's CI green.

Utility commands

  • Run codegen: cargo run --manifest-path /path/to/flutter_rust_bridge/frb_codegen/Cargo.toml -- generate
  • Run tests: ./frb_internal test-dart-native --package frb_example/dart_minimal

@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 0.16026% with 623 lines in your changes missing coverage. Please review.
✅ Project coverage is 1.83%. Comparing base (67bfaec) to head (ee99ac3).

Files with missing lines Patch % Lines
.../codegen/parser/mir/parser/ty/type_substitution.rs 0.00% 174 Missing ⚠️
...ibrary/codegen/parser/mir/parser/ty/enumeration.rs 0.00% 125 Missing ⚠️
.../library/codegen/parser/mir/parser/ty/structure.rs 0.00% 122 Missing ⚠️
...gen/src/library/codegen/parser/mir/parser/ty/ty.rs 0.00% 86 Missing ⚠️
...rc/library/utils/dart_repository/dart_toolchain.rs 0.00% 16 Missing ⚠️
...c/library/codegen/parser/mir/parser/ty/generics.rs 0.00% 15 Missing ⚠️
...b_codegen/src/library/codegen/ir/mir/ty/generic.rs 0.00% 13 Missing ⚠️
...ary/codegen/parser/mir/parser/ty/enum_or_struct.rs 0.00% 13 Missing ⚠️
...en/src/library/codegen/parser/mir/parser/ty/mod.rs 0.00% 8 Missing ⚠️
...rc/library/codegen/parser/mir/parser/extra_type.rs 0.00% 7 Missing ⚠️
... and 16 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Nov 22, 2025

Great job! Feel free to ping me if need any suggestions

@nightscape nightscape force-pushed the generic-enums-with-concrete-type-aliases branch 5 times, most recently from 266e522 to 53faf68 Compare November 23, 2025 13:32
@nightscape nightscape force-pushed the generic-enums-with-concrete-type-aliases branch 7 times, most recently from 1dca824 to 7923a8e Compare November 29, 2025 22:32
@nightscape nightscape force-pushed the generic-enums-with-concrete-type-aliases branch from 7923a8e to b2f8b1e Compare December 4, 2025 22:37
@nightscape
Copy link
Author

@fzyzcjy I've made a few more fixes and it works reliably now for my use case.
Would you mind having a look?

@nightscape nightscape marked this pull request as ready for review December 4, 2025 22:37
Copilot AI review requested due to automatic review settings December 4, 2025 22:37
Copy link

Copilot AI left a 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.

Copy link
Owner

@fzyzcjy fzyzcjy left a 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> {
Copy link
Owner

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> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe AnotherBatchTwiNormal

Copy link
Owner

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)

Copy link

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree!

@nightscape nightscape force-pushed the generic-enums-with-concrete-type-aliases branch from b2f8b1e to ee99ac3 Compare January 2, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow frb mirror on concrete generic enum

3 participants