-
Notifications
You must be signed in to change notification settings - Fork 11
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
Use staged_builder #349
Use staged_builder #349
Conversation
Generate changelog in
|
#[builder(default, into)] | ||
item: Option<conjure_object::Any>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can it just do into
here, whereas the Any type in a map or vec needs a customer serializer like https://github.com/palantir/conjure-rust/pull/349/files#diff-8fcc3688b43688b6b278cb5ba8f57cc9c0446f2b1200d948142255818816227cR11-R17?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside, could we just define the custom serializer once somewhere so it doesn't have to keep redefining it? The other conjure_object types only have the #[builder()]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think this is specific to the Option
, because conjure_object::Any
has the custom serializer here https://github.com/palantir/conjure-rust/pull/349/files#diff-450a3ab87b025c7854669c7345e9221165642460bc03581346e2ed08db393726R11-R18
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use into
for places where we want the conversion logic to just use an Into
implementation.
You can see in the deleted manual builder code below that the behavior here matches what we were doing previously.
pub struct SafeLongExample { | ||
#[builder()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that most of the conjure_object
types don't need to specify into
here. What makes that possible, whereas the String
type does need the into
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on what conversion behavior we want to support for the setter. With an e.g. i32
we just take that type directly, whereas for string we take impl Into<String>
so you can pass in e.g. string literals directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty #[builder()]
attributes aren't necessary - I pushed up a commit to remove them.
Before this PR
We directly codegened staged builder logic, with each stage being a separate type.
Constructors were generated for all types which had 3 or fewer fields, and the constructor required all of them.
After this PR
==COMMIT_MSG==
Object builders are now generated with
#[staged_builder]
. Constructors now ignore optional fields.==COMMIT_MSG==
The builders generated by
#[staged_builder]
are much cleaner in rustdoc output, as all of the setters are rendered on one page: https://docs.rs/staged-builder/latest/staged_builder/example_person/struct.Builder.htmlPossible downsides?
The constructor change will be a someone nontrivial source break, but should make wire-compatible evolution of Conjure objects less likely to be a Rust-incompatible change.
Closes #347
Closes #348