-
Notifications
You must be signed in to change notification settings - Fork 305
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
Crate compilation error when using mirrored third party Enum in StreamSink #1839
Comments
Hmm, do you mean it is OK if we do either be return value or be in stream sink, but error if we do both; Or can the minimal reproducible sample be further reduced to halves?
If your enum does not support clone (or have other special properties), maybe just make it opaque instead of mirroring it. |
The error happens as long as there is a mirrored Enum used in a StreamSink, even if the mirrored Enum is never used as a return value. Cargo check shows that the compilation error is within the generated code when instantiating the actual StreamSink during the StreamSink::new(
context
.rust2dart_context()
.stream_sink::<_, MyEnum>(),
) If |
While messing around with the generated code, it looks like the crate can compile if I manually changed the following. StreamSink::new(
context
.rust2dart_context()
.stream_sink::<_, mirror_MyEnum>(), // codegen had MyEnum as the generic type originally
) Additionally, not sure if I encountered the same issue but in another way, I'm getting the same compilation error if there is a #[flutter_rust_bridge::frb(opaque)]
pub struct TestStruct {}
pub fn stream_struct(_sink: StreamSink<TestStruct>) {}
pub fn stream_struct_option(_sink: StreamSink<Option<TestStruct>>) {} I looked at the StreamSink instantiation for frb_generated.rsfn wire_stream_struct_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
data_len_: i32,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec,_,_>(flutter_rust_bridge::for_generated::TaskInfo{ debug_name: "stream_struct", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream }, move || {
let message = unsafe { flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(ptr_, rust_vec_len_, data_len_) };
let mut deserializer = flutter_rust_bridge::for_generated::SseDeserializer::new(message);
deserializer.end(); move |context| {
transform_result_sse((move || {
Result::<_,()>::Ok(crate::api::simple::stream_struct(StreamSink::new(context.rust2dart_context().stream_sink::<_,Local_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockTestStruct>())))
})())
} })
}
fn wire_stream_struct_option_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
rust_vec_len_: i32,
data_len_: i32,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "stream_struct_option",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream,
},
move || {
let message = unsafe {
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
ptr_,
rust_vec_len_,
data_len_,
)
};
let mut deserializer =
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
deserializer.end();
move |context| {
transform_result_sse((move || {
Result::<_, ()>::Ok(crate::api::simple::stream_struct_option(StreamSink::new(
context
.rust2dart_context()
.stream_sink::<_, Option<TestStruct>>(), // <---- Problematic?
)))
})())
}
},
)
} |
Briefly check it and it looks like it should be Feel free to PR to fix it! Alternatively I will work on it in the next batch (hopefully within several days)
Good observation! Then looks like it is missing generating this. |
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. |
Describe the bug
Encountered a rust compilation error when I had both a function to return a third-party Enum to Dart land and a function that writes said Enum to a
StreamSink
.cargo check errors
Also, while preparing this repro, I noticed that apparently the mirrored 3rd party type must also implement Clone due to a derive(Clone) in
frb_generated.rs
, is this intended?Steps to reproduce
flutter_rust_bridge_codegen create repro_frb
cd repro_frb
cargo new --lib rust-3rdparty
rust-3rdparty/src/lib.rs
rust/Cargo.toml
to have dependency onrust-3rdparty
rust/src/api/simple.rs
flutter_rust_bridge_codegen generate
Logs
Expected behavior
Rust bridge can compile
Generated binding code
No response
OS
Windows
Version of
flutter_rust_bridge_codegen
2.0.0-dev.28
Flutter info
No response
Version of
clang++
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: