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

Deserialization error when passing rust variant enums #9

Closed
jc324 opened this issue Apr 15, 2022 · 3 comments
Closed

Deserialization error when passing rust variant enums #9

jc324 opened this issue Apr 15, 2022 · 3 comments

Comments

@jc324
Copy link

jc324 commented Apr 15, 2022

With Membrane, there seems to be a deserialization issue on the dart side when passing rust variant enums:

#[dart_enum(namespace = "ast")]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum Stmt {
    ExpStmt(Expr),
}

Error:

Unhandled exception:
Exception: Unknown variant index for Expr: 56542
@jerel
Copy link
Owner

jerel commented Apr 16, 2022

Thanks for the report, do you have your project configured with Membrane::new().with_c_style_enums(false) or .with_c_style_enums(true) (the default)? Or another way to ask this, are Dart enums or Dart classes being generated?

@jc324
Copy link
Author

jc324 commented Apr 16, 2022

Here's my config, I think it's on the default:

let mut project = membrane::Membrane::new();
project
    .timeout(200)
    .package_destination_dir(".")
    .package_name("test")
    .using_lib("libtest")
    .create_pub_package()
    .write_api()
    .write_c_headers()
    .write_bindings();

BTW, Dart enums are generated.

@jerel
Copy link
Owner

jerel commented Jul 13, 2022

Sorry for the slow response, I thought I had responded to you earlier. To solve this you'll need to add .with_c_style_enums(false) to the config so that classes are generated instead of Dart enums. Dart enums are unable to hold data which is what your enum definition requires.

I'll see if I can improve the compiler error messaging around this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants