Skip to content
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

Allow rust2dart to take precedence over other sources for the same type #2278

Open
aran opened this issue Sep 5, 2024 · 3 comments
Open
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc experimental feature Issues related to experimental instead of stable features

Comments

@aran
Copy link
Contributor

aran commented Sep 5, 2024

Is your feature request related to a problem? Please describe.
crate 'proto' has type P.
crate 'api', a rust_input, does 'pub use P' and has a rust2dart() implementation. Everything is good here.
Now we add crate 'newimport', a new rust_input, has a struct which includes a proto::P.

...frb_generated.rs:
error[E0119]: conflicting implementations of trait SseDecode for type P.

One implementation is the correct one, with the rust2dart implementation. The other is a standard generated one.

Describe the solution you'd like
When a type has a rust2dart implementation configured, use it everywhere for that type.

Describe alternatives you've considered
N/A
Additional context
N/A

@aran aran added the enhancement New feature or request label Sep 5, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 5, 2024

Looks like this is because frb does not handle each and every corner case of use, and the primary use case is single-crate instead of crate-import-another-crate-import-yet-another-crate. Indeed scanning a whole 3rd party crate is an experimental feature.

The simplest way may be avoid using too many crates which may confuse frb. Also feel free to PR to enhance this "scanning 3rd party crate" experimental feature!

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Sep 5, 2024
@aran
Copy link
Contributor Author

aran commented Sep 5, 2024

Makes sense. To explain a little more, the main way I have been using FRB is there is some various Rust code not in the flutter project, there is the flutter project separately, and in the flutter project there is a single crate which has dependencies out to the rest of the Rust code. The Flutter project's crate is thin glue code, that's where I've been specifying mirror, external, dart2rust etc over the types to get FRB to generate the Dart code.

I'm also thinking that if I put some_crate::some_module on rust_input, it may change the behavior of FRB even for some_crate::another_module?

@fzyzcjy
Copy link
Owner

fzyzcjy commented Sep 5, 2024

I see - that looks like a good use of "scanning 3rd party crate" experimental feature!

Another way may be, can you ensure you only have two crates: One for flutter (and frb), another for pure Rust. Then frb may be less confused when scanning the 3rd party crate.

I'm also thinking that if I put some_crate::some_module on rust_input, it may change the behavior of FRB even for some_crate::another_module?

Not very sure about the question, but frb does scan whole crate for struct information, since a function in some_crate::some_module may use structs in some_crate::another_module. And again, we cannot make breaking changes (until 3.0) so we may need to keep this (usually pretty reasonable) behavior.

@fzyzcjy fzyzcjy changed the title Allow rust2dart to take precedence over other sources for the same type [experimental-feature] Allow rust2dart to take precedence over other sources for the same type Sep 11, 2024
@fzyzcjy fzyzcjy added experimental feature Issues related to experimental instead of stable features and removed enhancement New feature or request labels Nov 5, 2024
@fzyzcjy fzyzcjy changed the title [experimental-feature] Allow rust2dart to take precedence over other sources for the same type Allow rust2dart to take precedence over other sources for the same type Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc experimental feature Issues related to experimental instead of stable features
Projects
None yet
Development

No branches or pull requests

2 participants