Skip to content
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

Codegen generating void? #2500

Open
thunderstorm010 opened this issue Jan 15, 2025 · 1 comment
Open

Codegen generating void? #2500

thunderstorm010 opened this issue Jan 15, 2025 · 1 comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@thunderstorm010
Copy link

Describe the bug

Rust type:
pub async fn set_motor(&self, idx: u8, pct: f32, rev: bool) -> Option<()>
Dart type:
Future<void?> setMotor({required int idx , required double pct , required bool rev });

Solution: Convert rust Option<()> to dart bool, where true represents Ok(()) and false represents None.

Steps to reproduce

Create functions like in the description.

Logs

line 136, column 16 of lib/src/rust/frb_generated.io.dart: Operator declarations must be preceded by the keyword 'operator'.
    ╷
136 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                ^
    ╵
line 136, column 16 of lib/src/rust/frb_generated.io.dart: The string '?' isn't a user-definable operator.

136 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                ^

line 136, column 16 of lib/src/rust/frb_generated.io.dart: Methods must have an explicit list of parameters.

136 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                ^

line 136, column 18 of lib/src/rust/frb_generated.io.dart: A function body must be provided.

136 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

line 246, column 16 of lib/src/rust/frb_generated.io.dart: Operator declarations must be preceded by the keyword 'operator'.

246 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                ^

line 246, column 16 of lib/src/rust/frb_generated.io.dart: The string '?' isn't a user-definable operator.
    ╷
246 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                ^
    ╵
line 246, column 16 of lib/src/rust/frb_generated.io.dart: Methods must have an explicit list of parameters.
    ╷
246 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                ^
    ╵
line 246, column 18 of lib/src/rust/frb_generated.io.dart: A function body must be provided.
    ╷
246 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
line 358, column 53 of lib/src/rust/frb_generated.io.dart: Expected an identifier.
    ╷
358 │ @protected void sse_encode_opt_box_autoadd_unit(void? self, SseSerializer serializer);
    │                                                     ^
    ╵
line 358, column 55 of lib/src/rust/frb_generated.io.dart: Expected to find ')'.
    ╷
358 │ @protected void sse_encode_opt_box_autoadd_unit(void? self, SseSerializer serializer);
    │                                                       ^^^^
    ╵
Could not format because the source could not be parsed:

line 20, column 29 of lib/src/rust/api/vehicle/motor_testing.dart: Expected to find '>'.
   ╷
20 │                      Future<void?>  close();
   │                             ^^^^
   ╵
line 23, column 9 of lib/src/rust/api/vehicle/motor_testing.dart: Expected to find '>'.
   ╷
23 │  Future<void?>  setMotor({required int idx , required double pct , required bool rev });
   │         ^^^^
   ╵
Could not format because the source could not be parsed:

line 112, column 8 of lib/src/rust/frb_generated.dart: Expected to find '>'.
    ╷
112 │ Future<void?> crateApiVehicleMotorTestingMotorTestManagerClose({required MotorTestManager that });
    │        ^^^^
    ╵
line 114, column 8 of lib/src/rust/frb_generated.dart: Expected to find '>'.
    ╷
114 │ Future<void?> crateApiVehicleMotorTestingMotorTestManagerSetMotor({required MotorTestManager that , required int idx , required double pct , required bool rev });
    │        ^^^^
    ╵
line 544, column 18 of lib/src/rust/frb_generated.dart: Expected to find '>'.
    ╷
544 │ @override Future<void?> crateApiVehicleMotorTestingMotorTestManagerClose({required MotorTestManager that })  { return handler.executeNormal(NormalTask(
    │                  ^^^^
    ╵
line 569, column 18 of lib/src/rust/frb_generated.dart: Expected to find '>'.
    ╷
569 │ @override Future<void?> crateApiVehicleMotorTestingMotorTestManagerSetMotor({required MotorTestManager that , required int idx , required double pct , required bool rev })  { return handler.executeNormal(NormalTask(
    │                  ^^^^
    ╵
line 1310, column 15 of lib/src/rust/frb_generated.dart: Expected a type name.
     ╷
1310 │ return raw as void; }
     │               ^^^^
     ╵
line 1361, column 16 of lib/src/rust/frb_generated.dart: Operator declarations must be preceded by the keyword 'operator'.
     ╷
1361 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw){ // Codec=Dco (DartCObject based), see doc to use other codecs
     │                ^
     ╵
line 1361, column 16 of lib/src/rust/frb_generated.dart: The string '?' isn't a user-definable operator.

1361 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw){ // Codec=Dco (DartCObject based), see doc to use other codecs
     │                ^

line 1361, column 16 of lib/src/rust/frb_generated.dart: Methods must have an explicit list of parameters.

1361 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw){ // Codec=Dco (DartCObject based), see doc to use other codecs
     │                ^

line 1361, column 18 of lib/src/rust/frb_generated.dart: A function body must be provided.

1361 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw){ // Codec=Dco (DartCObject based), see doc to use other codecs
     │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

line 1586, column 16 of lib/src/rust/frb_generated.dart: Operator declarations must be preceded by the keyword 'operator'.

1586 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer){ // Codec=Sse (Serialization based), see doc to use other codecs
     │                ^

(7 more errors...)
Could not format because the source could not be parsed:

line 139, column 16 of lib/src/rust/frb_generated.web.dart: Operator declarations must be preceded by the keyword 'operator'.

139 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                ^

line 139, column 16 of lib/src/rust/frb_generated.web.dart: The string '?' isn't a user-definable operator.
    ╷
139 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                ^
    ╵
line 139, column 16 of lib/src/rust/frb_generated.web.dart: Methods must have an explicit list of parameters.
    ╷
139 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                ^
    ╵
line 139, column 18 of lib/src/rust/frb_generated.web.dart: A function body must be provided.
    ╷
139 │ @protected void? dco_decode_opt_box_autoadd_unit(dynamic raw);
    │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ╵
line 249, column 16 of lib/src/rust/frb_generated.web.dart: Operator declarations must be preceded by the keyword 'operator'.
    ╷
249 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                ^
    ╵
line 249, column 16 of lib/src/rust/frb_generated.web.dart: The string '?' isn't a user-definable operator.

249 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                ^

line 249, column 16 of lib/src/rust/frb_generated.web.dart: Methods must have an explicit list of parameters.

249 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                ^

line 249, column 18 of lib/src/rust/frb_generated.web.dart: A function body must be provided.

249 │ @protected void? sse_decode_opt_box_autoadd_unit(SseDeserializer deserializer);
    │                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

line 361, column 53 of lib/src/rust/frb_generated.web.dart: Expected an identifier.

361 │ @protected void sse_encode_opt_box_autoadd_unit(void? self, SseSerializer serializer);
    │                                                     ^

line 361, column 55 of lib/src/rust/frb_generated.web.dart: Expected to find ')'.

361 │ @protected void sse_encode_opt_box_autoadd_unit(void? self, SseSerializer serializer);
    │                                                       ^^^^

)

Expected behavior

Option<()> -> bool

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

@thunderstorm010 thunderstorm010 added the bug Something isn't working label Jan 15, 2025
@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 15, 2025

Hmm, is it possible to make the return type bool (instead of Option<()>)?

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants