feat(build): Expose prost-build type_attributes and field_attribu…#60
Merged
LucioFranco merged 2 commits intohyperium:masterfrom Oct 8, 2019
Merged
feat(build): Expose prost-build type_attributes and field_attribu…#60LucioFranco merged 2 commits intohyperium:masterfrom
LucioFranco merged 2 commits intohyperium:masterfrom
Conversation
When generating ctags/universal-ctags, a 'tags' file is generated. This commit adds any generted 'tags' file to .gitignore.
This commit exposes the `type_attribute` and `field_attribute`
configuration settings from Prost. These are useful to tweak/extend the
generated types.
For example:
```
tonic_build::configure()
.out_dir(tmp)
.format(false)
.type_attribute(".", "#[derive(Serialize, Deserialize)]")
.type_attribute(".", "#[serde(rename_all = \"camelCase\")]")
.field_attribute("in", "#[serde(rename = \"in\")]")
.compile(&["tests/protos/wellknown.proto"], &["tests/protos"])
.unwrap();
```
Would add the serde `Serialize` and `Deserialize` traits, while renaming
all the fields to camelCase, and having serde keep fields named `in`
named `in`, rather than Prost's `in_`, to every type generated by Prost.
blittable
pushed a commit
to blittable/tonic
that referenced
this pull request
Oct 22, 2019
…yperium#60) * chore: Add tags to .gitignore When generating ctags/universal-ctags, a 'tags' file is generated. This commit adds any generted 'tags' file to .gitignore. * feat(build): Expose type_attribute and field_attribute This commit exposes the `type_attribute` and `field_attribute` configuration settings from Prost. These are useful to tweak/extend the generated types. For example: ``` tonic_build::configure() .out_dir(tmp) .format(false) .type_attribute(".", "#[derive(Serialize, Deserialize)]") .type_attribute(".", "#[serde(rename_all = \"camelCase\")]") .field_attribute("in", "#[serde(rename = \"in\")]") .compile(&["tests/protos/wellknown.proto"], &["tests/protos"]) .unwrap(); ``` Would add the serde `Serialize` and `Deserialize` traits, while renaming all the fields to camelCase, and having serde keep fields named `in` named `in`, rather than Prost's `in_`, to every type generated by Prost.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
When using tonic, you sometimes want to also serialize the generated types with Serde.
Solution
Expose the underlying
prost-build.Configoptions fortype_attributesandfield_attributes, which allows you to extend the generated types.Would make the resulting generated code serializable, deserializable, camelCase, and preserve 'in' vs the prost generated 'in_'.