-
Notifications
You must be signed in to change notification settings - Fork 28
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
WIP: Replace builder to improve ergonomics #66
Conversation
Before I proceed with this, I'll wait for opinions from @tychedelia and @rukai |
Personally I think this is fantastic and should give a huge improvement to ergonomics and hopefully a nice improvement to compile times too. I'll take a closer look at the list/maps open question when I get some time. |
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.
Definitely in favor of removing the proc macro and rolling our own. I much prefer the builder versions personally, so I think it's worth thinking about what the right API is.
The main thing I'd like us to get right is accepting Into
conversions where it makes sense as well as a good pattern for collections. My sense is that insert_foo
style methods are less helpful when you're trying to map another collection into a message field, although they could definitely still be useful for more imperative message building.
One thing I might suggest is just running cargo expand
and seeing any interesting tricks derive_builder is using that we could copy.
Would appreciate others thoughts and will try to think about this more closely this week. :)
I think the Most likely you have one of:
Both of which will just preallocate the resulting vec to the exact required size. Worst case you need to do something like: let partitions = vec!();
if some_condition {
partitions.insert(..)
}
TopicProduceData::default().with_partition_data(partitions); Which I think is a reasonable trade off for keeping our builder API simple. |
Doc comments would be great. /// Sets the $field to the passed value.
/// $documentation_for_field_taken_from_the_json
|
This reverts commit 8522410.
I initially wanted I believe the last thing is figuring out if these methods should take a generic |
I had a go at porting our project to the new builder API: it compiles, all tests pass and the code is much cleaner. Personally I would vote to not make use of |
How do we feel about landing this PR as it is and then exploring further changes in follow up PRs? |
Hey, sorry, for some reason I got unsubscribed from the PR and was on vacation. Let me give this a look today and will merge if it seems like a good starting point. I'd like to release the next milestone for y'all! |
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 generator implementation looks good to me.
I tested the readme sample code compiles as well.
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.
There are some minor nits I have still re: the redundancy of with_
prefix, but this looks fine to me and changing most of this in the future would be a mechanical refactor in a breaking release so probably fine. Agree this is a good base for future improvements, so am going to merge as is! Thanks for taking this on @Hackzzila
@rukai @Hackzzila released |
thanks! |
This is my take on #41. It replaces the builders with methods like this:
Then you can use
Default
and still have builder-like code.Examples
Before:
After:
Before:
After:
Open Questions
RIght now the following methods are generated for
Vec<T>
types (and similar for Maps, but with a key)Alternatively (or in addition) you could add a
extend_{field}
method that takesimpl IntoIterator<Item = {type}>