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

Refactor generated builder set methods to always take Option #506

Merged
merged 4 commits into from
Jun 18, 2021
Merged

Refactor generated builder set methods to always take Option #506

merged 4 commits into from
Jun 18, 2021

Conversation

jdisanti
Copy link
Collaborator

This is a breaking change: All set_* methods on builders and clients will take an Option<T> where they sometimes used to take a T.

This is a refactor that will make it possible to simplify the code in #498. It also simplifies some existing code, such as the parsing of HTTP headers into non-optional values. Now the error handling for that lives in the builder rather than in the header parsing.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jdisanti jdisanti requested a review from rcoh June 15, 2021 23:13
Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we added something like:

BuilderGenerator.callSetter(memberShape: MemberShape, symbol: Symbol) {
  rust("args")
}

that handles the option wrapping in one place? When we needed to force optionality, you could pass symbol.asOptional() (symbol.letIf(forceOptional) { it.asOptional() } is pretty clean)

As a separate issue, we probably should add builders for unions.

@jdisanti
Copy link
Collaborator Author

After examining it, I think I'm going to hold off on creating a common BuilderGenerator.callSetter. It would definitely benefit the SerdeJsonSerializerGenerator, but that's not going to be sticking around. I'll keep it in mind though as it may also benefit the new JsonSerializerGenerator in my other PR.

@jdisanti jdisanti merged commit 97134ee into smithy-lang:main Jun 18, 2021
@jdisanti jdisanti deleted the builder-set-always-optional branch June 18, 2021 21:48
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