Add an option to make struct fields public #522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this PR
Like in Conjure-Java, we made generated objects immutable with a builder API. This makes the structs a bit more annoying to work with, since you can't directly mutate them and can't move out of them. Since Rust has a robust ownership model, the need for immutable types is not as large as it is in Java.
After this PR
==COMMIT_MSG==
Added a
publicFieldscodegen option that replaces struct accessor methods with public fields.==COMMIT_MSG==
The builder types are still around, and since we mark the structs
#[non_exhaustive], are the only way to construct objects. This makes it a bit easier to add new fields to objects without breaking builds, and are generally a bit easier to work with since the builder methods handle things like type conversions.To preserve backwards compatibility, the option is disabled by default, but I think we may want to make this how we do things moving forward.
Possible downsides?
We're now publicly exposing the fact that struct and union fields are boxed internally. We do this to both keep the shallow struct size from getting too enormous and to avoid infinite sizes for recursive APIs.
Closes #304