-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(twilight-model)!: Implement additional select menu types (#2219)
* feat(twilight-model)!: Implement additional select menu types This patch implements the additional select menu types `user`, `role`, `mentionable`, and `channel`. Moreover, it moves the type-specific data for the existing text select menu implementation into a separate enum variant. The new types are implemented by "semi-flattening" the `SelectMenu` struct: fields common to all select menu types are implemented in the struct itself, and type-specific fields like the available options or channel types are moved into a `SelectMenuData` enum. This enum is also used to select a select menu's type. This approach de-duplicates the common fields while preventing users from accessing fields irrelevant to the current select menu type. Finally, this commit updates the documentation and existing tests to reflect these changes. The tests, however, might require additional attention in case new behaviour introduced by this commit should be tested as well. * refactor(twilight-model): Use unreachable! in ComponentVisitor This patch makes `ComponentVisitor::visit_map` use `unreachable!` instead of `panic!` in case a select menu type was not implemented while being listed in a previous match statement. Moreover, this commit sneaks in a minor formatting fix inside `Components` doc-comment example. * feat(twilight-model)!: Implement `resolved` for select menu interactions This commit implements the `resolved` field for `MessageComponentInteraction`. This field holds resolved users, roles, channels, or attachments for select menu interactions. Unfortunately, the new field makes it impossible to implement `Eq` and `Hash` for `MessageComponentInteractionData`. * test(twilight-model): Fix tests for `InteractionDataResolved` This commit fixes the tests testing the (de-)serialization of `InteractionDataResolved`. Previously, the tests were failing, as the type was renamed from `CommandInteractionDataResolved`. Moreover, this commit fixes the message component interaction tests by adding the missing `resolved` field to the expected fields in `message_component_interaction_data`. * refactor(twilight-model)!: Un-`Box` `SelectMenuData` variants This commit unboxes `SelectMenuData`'s variants. They were boxed in a previous patch to prevent future fields from unnecessarily increasing the enum's memory footprint, but considering that, with the current structures, new fields are a breaking change already, it's OK to leave the variants unboxed for now and re-box as necessary. For the current code, this saves a heap allocation while only marginally increasing the enum's memory footprint. This change is only breaking in the context of PR #2219. When added to the commits in this PR, it doesn't add any breaking changes to the PR's list of breaking changes. * refactor(twilight-model)!: Fully flatten SelectMenu This commit removes the SelectMenuData type and embeds all variant-specific fields in the base struct. Moreover, it adds documentation indicating which fields are required variant-specific fields. This commit also updates the component validation module in `twilight-validate` by introducing a new error type for text select menus that don't have the necessary `options` field. * docs(twilight-model)!: Streamline select menu documentation This commit streamlines the language in the `SelectMenu` and `SelectMenuType` documentation. In particular, it removes duplicated sections outlining required and optional fields. Moreover, it makes language describing which menu types use a specific option more in line with the rest of the library.
- Loading branch information
1 parent
fc1a1d2
commit 089b84d
Showing
12 changed files
with
260 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.