serenity
serenity copied to clipboard
Enforce required fields for builders
This PR adds enforcement for unconditionally required fields on builders. It does so by removing the implementation of Default on those builders and adding a new method that takes the required fields as argument. The following builders have been changed as such:
AddMember
CreateChannel
CreateScheduledEvent
CreateSticker
CreateThread
CreateStageInstance
CreateWebhook
CreateApplicationCommand
CreateApplicationCommandOption
CreateButton
CreateInputText
CreateSelectMenu
CreateSelectMenuOption
CreateEmbedAuthor
CreateEmbedFooter
All other builders have retained their implementations of Default, but I've added a new method to them as well that simply wraps Self::default. A few things to note are:
EditAutoModRulehas been left untouched, however it should be noted that creating an automoderation rule has some required fields, whereas modifying one does not. Potentially it might be worth it to add a newCreateAutoModRulebuilder, although that would introduce a good bit of code duplication.- Renamed
EditRole::newtoEditRole::from_roleto be more descriptive, and changedEditRole::newto wrapEditRole::default. - This PR does not add enforcement of conditionally required fields (such as for
CreateMessageand others where one ofcontent,embeds, orattachmentsis required). Doing so would (I think) require using a typestate pattern, so should be done in a separate PR, if at all.
Bikeshedding on parameter order for the newly enforced fields in each Builder::new method is appreciated. I've done my best to order them based on some intuitive sense of hierarchy.