fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.12k stars 283 forks source link

Support `SyncReturn<Struct>, SyncReturn<Enum>` #935

Closed rogurotus closed 1 year ago

rogurotus commented 1 year ago

SyncReturn has been recently redesigned (thanks @ngasull for the great implementation) judging by the implementation, it became possible to use SyncReturn(Struct) SyncReturn(Enum), but for some reason I do not understand, this is restricted.

The restriction is imposed here. frb_rust/src/lib.rs

/// Use this struct in return type of your function, in order to tell the code generator
/// the function should return synchronously. Otherwise, it is by default asynchronously.
pub struct SyncReturn<T: IntoDart>(pub T);

although frb generates IntoDart and if you do pub struct SyncReturn<T>(pub T); in SyncReturn it will be possible to use structure

fzyzcjy commented 1 year ago

IMHO it should be possible to use struct/enum in sync return as well. What error does it generate when doing so?

rogurotus commented 1 year ago

In general, I understood this works when the implementation is already there, but if you are generating for the first time then the error is caught before the code is generated

error like this

pub struct SyncReturn<T: IntoDart>(pub T);
     |                          ^^^^^^^^ required by this bound in `flutter_rust_bridge::SyncReturn`

In theory, we can remove the restriction from struct SyncReturn since there is already an IntoDart restriction in the generated code

fzyzcjy commented 1 year ago

Feel free to PR! (and let's see how CI says - if CI is happy then IMHO this should be ok)

github-actions[bot] commented 1 year ago

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.