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.29k stars 301 forks source link

frb_generated error for protobuf messages with same name but different struct #2355

Closed jhlee0133 closed 1 month ago

jhlee0133 commented 1 month ago

Describe the bug

when using two protobuf files (a.proto and b.proto) that define response messages with the same name but different structures and generating _frb_generated.rs_ file, the file produces a type mismatch error

a.proto:

syntax = "proto3";
package service_a;

service ServiceA {
    rpc Echo(ARequest) returns (SameResponseName) {}
}

message ARequest {
    string message = 1;
}

// Struct name is the same as in ServiceB, but structure is different
message SameResponseName {
    string a_string = 1;
}

b.proto:

syntax = "proto3";
package service_b;

service ServiceB {
    rpc Echo(BRequest) returns (SameResponseName) {}
}

message BRequest {
    string message = 1;
}

// Struct name is the same as in ServiceA, but structure is different
message SameResponseName {
    int32 b_int = 1;
}

api:


// Implementation for service_a
pub async fn service_a_echo(request: a::ARequest) -> Result<a::SameResponseName> {
    Ok(a::SameResponseName {
        a_string: request.message,
    })
}

// Implementation for service_b
pub async fn service_b_echo(_request: b::BRequest) -> Result<b::SameResponseName> {
    Ok(b::SameResponseName { b_int: 1 })
}

frb_generated.rs error:

the trait bound `b::SameResponseName: SseEncode` is not satisfied
the following other types implement trait `SseEncode`:
  ()
  ARequest
  BRequest
  String
  Vec<u8>
  a::SameResponseName
  anyhow::Error
  bool
and 2 othersrustcClick for full compiler diagnostic
boilerplate.rs(106, 16): required by a bound in `transform_result_sse`

Steps to reproduce

https://github.com/jhlee0133/frb_example

Logs

the trait bound `b::SameResponseName: SseEncode` is not satisfied
the following other types implement trait `SseEncode`:
  ()
  ARequest
  BRequest
  String
  Vec<u8>
  a::SameResponseName
  anyhow::Error
  bool
and 2 othersrustcClick for full compiler diagnostic
boilerplate.rs(106, 16): required by a bound in `transform_result_sse`

Expected behavior

No response

Generated binding code

No response

OS

macOS 15.0.1

Version of flutter_rust_bridge_codegen

2.5.0

Flutter info

No response

Version of clang++

No response

Additional context

No response

welcome[bot] commented 1 month ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 1 month ago

Yes, currently frb does not distinguish same struct name in different files. This is because there can be complex nested use etc with edge cases. The simplest solution is to rename your structs to avoid name conflicts, or try to configure the protobuf codegen to add prefix.

jhlee0133 commented 1 month ago

Ok, thank you for your response.

fzyzcjy commented 1 month ago

You are welcome!

github-actions[bot] commented 2 weeks 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.