twilight-rs / twilight

Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.
https://discord.gg/twilight-rs
ISC License
670 stars 131 forks source link

feat(twilight-model,twilight-validate)!: Implement select menu default values #2281

Closed archer-321 closed 11 months ago

archer-321 commented 1 year ago

This pull request adds the default_values field Discord recently introduced for select menus. This field allows selecting default values for auto-populated select menu types (currently, user, role, mentionable, and channel).

Setting this field to Some(...) for any other select menu type is an error at runtime. However, I've changed the twilight-verify implementation to detect mistakes like this before sending the data to Discord.

Given the previous decision to implement select menu types as entirely flattened structs, I added the default_values field as an option to SelectMenu. While this doesn't statically enforce the type requirement explained above, this matches the behaviour of other type-specific fields.

Testing

I've updated my simple test project to use the feature introduced by this PR. As with my last PR, you can use it to get a quick overview of how the new API works.

Breaking changes

I'm aware of the following breaking change that this PR introduces:


I've updated the documentation and tests wherever necessary, but if I missed something or you want me to rephrase a comment, please request changes.

I believe you should add the d-api and d-breaking labels to this PR.

archer-321 commented 1 year ago

Interestingly enough, the test passed with the (outdated) version I had in my Cargo.lock file. After a quick cargo update, I could reproduce the failure and push a fix.

archer-321 commented 12 months ago

@laralove143, I could reproduce the CI failure locally (after setting the necessary environment variables). However, I believe this failure is unrelated to this PR, as the main branch seems to be failing with the same error. Maybe this was introduced by better/worse detection of unused exports in a nightly toolchain update? :thinking:

archer-321 commented 12 months ago

I believe the CI error this PR is experiencing will be fixed by #2295. I'll rebase the source branch of this PR once 2295 is merged :slightly_smiling_face:

archer-321 commented 12 months ago

I rebased the PR, and this fixed the CI. Please let me know if there are any other changes you'd like to see c: