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

Struct generation improvements #81

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

SlayerOfTheBad
Copy link
Contributor

This PR includes multiple improvements to virtue regarding the generation of Structs and Enums:

  1. It makes it possible for structs to have unnamed fields, or be a ZST (struct StructName;).
  2. It makes it possible for Enums to be generated, and all types of values therein.
  3. It makes it possible to generate Enums and Structs outside of a module.

Points 2 and 3 have been previously raised in #23.
Point 1 is just something I ran into personally.

Adds the possibility to make ZST structs and structs with unnamed
fields.
Backwards compability is insured by defaulting to `StructType::Named`,
which causes identical behaviour to before.
Adds an enum generator, based on the struct generator.
Previously, structs could only be generated inside a new module.
Sometimes, it is desirable to define a new struct in the same module as
the struct that is being derived on.
By dupicating the `generate_struct` function from `GenerateMod` to to
`Generator`, this is easily achieved.
@VictorKoenders
Copy link
Contributor

Would you mind adding examples that will also validate the generated code? An example can be found here

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

Attention: 108 lines in your changes are missing coverage. Please review.

Comparison is base (591ef63) 48.42% compared to head (0a26521) 46.23%.

❗ Current head 0a26521 differs from pull request most recent head 7643a70. Consider uploading reports for the commit 7643a70 to get more accurate results

Files Patch % Lines
src/generate/gen_enum.rs 0.00% 76 Missing ⚠️
src/generate/gen_struct.rs 0.00% 26 Missing ⚠️
src/generate/generator.rs 0.00% 4 Missing ⚠️
src/generate/generate_mod.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk      #81      +/-   ##
==========================================
- Coverage   48.42%   46.23%   -2.20%     
==========================================
  Files          20       21       +1     
  Lines        2030     2124      +94     
==========================================
- Hits          983      982       -1     
- Misses       1047     1142      +95     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SlayerOfTheBad
Copy link
Contributor Author

I have added doc comment tests that I believe cover all of the added functionality. Please let me know if I missed anything!

Add testcases for the struct and enum generators.
A Tuple struct is called a Tuple struct, not an unnamed field struct, so
it makes more sense for the function to be called `make_tuple`, in line
with `make_ZST`.
@VictorKoenders VictorKoenders merged commit de08068 into bincode-org:trunk Jan 16, 2024
7 checks passed
@VictorKoenders
Copy link
Contributor

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants