-
Notifications
You must be signed in to change notification settings - Fork 597
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
[DRAFT] Builder paradigm overhaul #1967
Conversation
71e567e
to
f81e5e9
Compare
I've rebased on |
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 builders should be made must_use
aswell, instead of each method on them, imo
f81e5e9
to
b78e540
Compare
c1c4768
to
5076f80
Compare
Makes `Builder::new()` public, and feature-gates things behind `http`, which is implied by `model`; this functionality is no longer tied to the actual model methods, so it's more appropriate.
b56e190
to
b5cb6a0
Compare
ab267b1
to
1175cdc
Compare
With the PR making good progress up to this point, I thought I'd write down some comments and concerns about the current state of the code.
|
3912a2f
to
5de0167
Compare
Removed the following: - `CreateEmbed::set_author` - `CreateEmbed::set_footer` - `CreateMessage::set_embed` - `EditMessage::set_embed` - `Embed::fake` Renamed the following: - `CreateMessage::set_embeds` -> `CreateMessage::embeds`
Of note: - Renamed `CreateMessage::set_sticker_ids` -> `CreateMessage::sticker_ids`
4baf5fb
to
060addd
Compare
Of note, changed `avatar` from `Option<Option<String>>` to just `Option<String>`.
060addd
to
806accb
Compare
Added `in_thread` and `wait` methods on the builder, and therefore removed `wait` as a parameter to the model method, and removed `execute_webhook_in_thread` since it became redundant.
One more issue to note about the |
I've thought of an approach that solves these problems. Unfortunately it requires redoing a large part of what has already been pushed here, so I'm closing this and trying again in a new PR. |
This is a draft PR as this work will not be ready all at once, and I'm open to comments and bikeshedding as we attempt to get this right. The main goal is to start addressing point number 3 listed in #1905: to rework the builder API to reduce monomorphization bloat (resulting from generic closure parameters), as well to allow for re-using preconstructed builders, and also to enable another later pass of changes to enforce (to a greater extent) API compliance at compile time using the builder API (e.g. always-required, conditionally-required, and mutually exclusive fields).
Some notable changes I've done:
execute
method that consumes them and actually perform the request. Essentially the functionality from the model types has been moved into the builder itself.execute
takes ownership ofself
, then in order to callBuilder::new().method1().method2().execute()
, the rest of the chain must take ownership as well. Therefore, builders will change to take and returnSelf
instead of&mut Self
.So far I've tried reworking
CreateSticker
andCreateThread
, with some success. I do have some concerns though:1. A good deal of builders are called from multiple places. For example,GuildId
/Guild
/PartialGuild
, orChannelId
/GuildChannel
. Since the implementations on guild usually do a cache lookup, to preserve all functionality I had to make the builder store a reference to a genericGuildIdWrapper
, which I will likely also have to do forChannelId
. Is this acceptable? I'm not yet satisfied with it as the implementation is exactly duplicated forGuild
andPartialGuild
, but that's something I may solve later, once I'm sure that this fact holds for all relevant builders.2. Do we want to factor out
execute
andinto their own traits, e.g.execute_with_cache
Builder<T>
and? We could probably auto-import these so that the user wouldn't have to import them themselves.BuilderWithCache<T>
3. The reason the
execute
method takes ownership is becausejson::hashmap_to_json_map()
consumes the builder's hashmap. Potentially this is addressed by #1962, so I'll wait until that PR is complete before getting too deep into the weeds on this one.Feedback very much wanted; I'm not great at writing docs so a review of that part is also greatly appreciated.