fzyzcjy / flutter_rust_bridge

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

rust function names clashes #1913

Closed patmuk closed 10 hours ago

patmuk commented 2 weeks ago

Describe the bug

When the same function name, but in different mods, is used, the rust generated code has a name clash.

This is the relevant part of the generated code:

fn wire_view_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: "view", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal }, 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::share_cycle::view())
                    })())
                } })
            }

fn wire_view_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: "view", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal }, 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::todo_list_api::view())
                    })())
                } })
            }

not the same function name wire_view_impl but different full qualified name of the rust function crate::api::share_cycle::view() vs crate::api::todo_list_api::view().

Steps to reproduce

create rust code with the same function name in two different mods.

Logs

rust compile error: error[E0428]: the name `wire_view_impl` is defined multiple times

Expected behavior

No response

Generated binding code

No response

OS

MacOS

Version of flutter_rust_bridge_codegen

2.0.0-dev.32

Flutter info

No response

Version of clang++

No response

Additional context

No response

aran commented 2 weeks ago

I also think I saw name resolution issues for structs with the same name in different mods, but I didn't have a chance to minimize and confirm yet.

fzyzcjy commented 2 weeks ago

Good point! This looks easily solvable, because we merely need to change the name from wire_view_impl to contain full names (e.g. wire_api_share_cycle_view_impl).

Feel free to PR (since this is not very hard); alternatively I will work on it in the next batch.

For completeness, the workaround (as you probably see) is to rename it temporarily.

fzyzcjy commented 1 week ago

@aran I also think I saw name resolution issues for structs with the same name in different mods

That one is indeed harder, because there is no easy way to understand which struct are users indeed using (there can be complex use ... chains), so currently the struct names have to be unique.

patmuk commented 10 hours ago

I forgot to reply! Yes, understandable and totally fine to use different names.

fzyzcjy commented 9 hours ago

No worries, it is implemented!