zefchain / serde-reflection

Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.
Apache License 2.0
124 stars 22 forks source link

Modify the Dart enum generation to match other usage of c_style_enum #15

Closed jerel closed 2 years ago

jerel commented 2 years ago

Summary

The C# implementation of enum generation looks at all variants of an enum and, if all are of type Unit, it then generates a native enum and otherwise generates a class. The current Dart implementation simply generates all classes if c_style_enums = false or all enums if c_style_enums = true.

This PR changes the Dart logic to match C# (the only other language that currently implements the c_style_enums config. dart.rs will now generate all classes if c_style_enums = false and if it is true it will generate native Dart enums unless the enum contains data, then it will generate a class.

Test Plan

A test was added that verifies that when c_style_enums is enabled the generator will generate native Dart enums for the simple case but generate classes for data-containing enums.

ma2bd commented 2 years ago

Thanks for the PR. Looks reasonable to me

ma2bd commented 2 years ago

Just released under serde-generate 0.24.0

jerel commented 2 years ago

Excellent, thanks for this!