-
Notifications
You must be signed in to change notification settings - Fork 469
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
Extend prost-build to generate message builders #901
Open
mzabaluev
wants to merge
6
commits into
tokio-rs:master
Choose a base branch
from
mzabaluev:builders
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Commits on May 9, 2024
-
prost-build: optionally generate builder API
For each message, optionally generate a struct to provide the forward-compatible builder API, with inherent methods for field setters and the .build() method to produce the fully initialized message struct. If generation of builders is enabled with a name `Builder` for a message named `Foo`, an impl block with the associated fn `Foo::builder()` is appended to the top-level file scope, and the definition of the builder struct `Builder` and its methods is appended to the module `foo`. Reuse the helpers that generate field definitions for a message, but use a mode to output code for the builder fields, which must be private and devoid of docs and prost annotations. The added Config::builder method populates a PathMap with values given in the second argument to configure the builder name.
Configuration menu - View commit details
-
Copy full SHA for 545dd42 - Browse repository at this point
Copy the full SHA 545dd42View commit details -
tests: test the generated builders
Adorn a struct with #[non_exhaustive] to showcase and test how the builder API (and Default) can be used to forward-compatibly construct values of generated message types, while the struct initializer syntax is forbidden. Some of the doc tests showcase working around name conflicts between the associated function generated for the builder API and a getter method generated by the Message derive for a field named `builder`. Also verify the no-conflict case where the field does not have a getter generated for it, so the `builder` associated fn is fine. The test crates in tests-2015 and tests-no-std are uniformly named "tests" to simplify boilerplate in the doc tests.
Configuration menu - View commit details
-
Copy full SHA for 35c98a4 - Browse repository at this point
Copy the full SHA 35c98a4View commit details -
prost-build: generate From<Builder> impls
This allows plugging a message builder into other builders' setters for fields of the message type without the need to call .build().
Configuration menu - View commit details
-
Copy full SHA for 182d22a - Browse repository at this point
Copy the full SHA 182d22aView commit details -
Test builder for field name that is a keyword
The setter for field named `test` in proto must be named `r#test`.
Configuration menu - View commit details
-
Copy full SHA for 6a16716 - Browse repository at this point
Copy the full SHA 6a16716View commit details -
Configuration menu - View commit details
-
Copy full SHA for 91036e3 - Browse repository at this point
Copy the full SHA 91036e3View commit details
Commits on May 12, 2024
-
Configuration menu - View commit details
-
Copy full SHA for b525600 - Browse repository at this point
Copy the full SHA b525600View commit details
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.