RFC: Location for model builders #1056
Replies: 7 comments 14 replies
-
Moving related builders in other crates would require mentioning them in the docs where they’re can be used, otherwise people would have to manually check and remember what builders are available. Also the structs returned from Client methods implementing Future kind of work like builders |
Beta Was this translation helpful? Give feedback.
-
My take is that we should have builders that perform validation in the model crate. Creating validated models is important for avoiding 400 errors so it makes sense to make it first-class with the models themselves. However, builders that are purely for ergonomic purposes should probably go in another crate like |
Beta Was this translation helpful? Give feedback.
-
Having builders doing validation when some http requests already do (see |
Beta Was this translation helpful? Give feedback.
-
I didn't discover My personal preference would be that, whatever the crate split, models with builders have an associated |
Beta Was this translation helpful? Give feedback.
-
I would like to call for a week long discussion period on the post and path forward I'm posting here. If we find severe issues we can change it and postpone, but if this sounds fine as-is I would like to move forward with it after a week. VocabularyCosmetic builder: a builder that does not perform validation and is purely to simplify initialization of a type or make it cleaner to read Long term planHere's what I believe the general "least controversial" long term consensus is based on current information and opinions while also getting stuff done:
Unanswered questions for another time (don't respond to these):
Short term planIn the short term what we should do is:
With regards to 2 (designing a util builder API), the API I'm thinking of is something like: #[cfg(feature = "builder")]
pub mod builder {
// Type being built is named `SomeCosmeticType`, so the module is named
// accordingly.
mod some_cosmetic_type {
/// Builder to construct a [`SomeCosmeticType`].
///
/// Because it's cosmetic and doesn't perform validation we don't need
/// an associated error type.
pub struct SomeCosmeticTypeBuilder;
}
pub use self::some_cosmetic_type::SomeCosmeticTypeBuilder;
} One week periodI would like one week of discussion to discuss this. If there's any major changes we can set this back, but if everyone is happy with this general plan I would like to create issues for all of these items and create a new GitHub project to track it. |
Beta Was this translation helpful? Give feedback.
-
What are the downsides of keeping cosmetic builders with the models that they build? It would aid discovery, and keep things consistent. |
Beta Was this translation helpful? Give feedback.
-
It has been one week. We will adopt these first steps and decide how to move forward after them. A project has been created: https://github.com/twilight-rs/twilight/projects/10 |
Beta Was this translation helpful? Give feedback.
-
Right now, we have a few different model builders in different places:
embed-builder
EmbedBuilder
model
AllowedMentionsBuilder
GuildChannelFieldsBuilder
RequestGuildMembersBuilder
There is (as of 2021-07-20) an open PR to add a
Command
builder tomodel
. Another aspect of this problem is that our builders perform validation tasks for HTTP requests.We need to decide what to do here to make things more consistent. From what I can see there are a few options.
util
crate, with their own separate featuresEmbed
builder to themodel
crate, which is consistent with the other builders(This relates to Unify validation errors into more concise error types #999 because at the moment we need to update two different const values to update the embed validation)
Edit: we'll hold off on making any changes related to this until after the next major release, as we already have enough breaking changes in
0.6
Beta Was this translation helpful? Give feedback.
All reactions