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

Support escaped names like `r#type` #2346

Closed poborin closed 2 weeks ago

poborin commented 1 month ago

Describe the bug

Given the struct contains an escaped name

struct A {
  pub r#type: String
}

When the FRB generates a Dart file it contains r#type filed while it should have a type

Steps to reproduce

in the Rust code use a reserved name such as:

  1. fileds
    struct A {
    pub r#type: String
    }
  2. function name
    fn #for() {}
  3. parameter name
    fn test(r#type: String) {}

    then run FRB generation

Logs

Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
   ╷
39 │  UserType get r#type;
   │                 ^^^^

----------------------------------

stderr=error: missing parameters for function definition
   --> .../rust/src/frb_generated.rs:464:69
    |
464 | ...   }fn wire__types__model__common__User_auto_accessor_get_r#type_impl(ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUin...
    |                                                               ^
    |
help: add a parameter list
    |
464 |             }fn wire__types__model__common__User_auto_accessor_get_r()#type_impl(ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,rust_vec_len_: i32,data_len_: i32) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse {
    |                                                                     ++

error: expected one of `->`, `<`, `where`, or `{`, found `#`
   --> .../rust/src/frb_generated.rs:464:69

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

fzyzcjy commented 1 month ago

Looks like a bug and feel free to PR for this! Alternatively I may work on it later. The workaround is to avoid such special names by renaming it.

github-actions[bot] commented 3 days 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.