-
Notifications
You must be signed in to change notification settings - Fork 575
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
SQLx encode/decode support #2514
Closed
Closed
Conversation
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 replaces the `[u64; 2]` shard info with `ShardInfo { id: u32, total: u32 }`. Co-authored-by: nickelc <[email protected]>
The `enum_number!` macro now takes the whole enum definition and generates `From` trait implementations to convert a value to the enum and back. The implementations can then be picked up by `serde` with `#[serde(from = "u8", into = "u8")]` to (de)serialize the types. ``` enum_number! { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[serde(from = "u8", into = "u8")] pub enum Foo { A = 1, B = 2, _ => Unknown(u8), } } ``` BREAKING CHANGE: The `Unknown` variant now takes the unknown value and the removed `fn num() -> u64` method can be replaced with `let v = u8::from(kind)`.
The returned `Result` is already marked as `#[must_use]`.
Both `Value` types implement `From` for their number variants.
The structs are almost identical except for the `focused` field for the current autocompleted option and that the `resolved` data map is not sent for autocomplete interactions. The entities from the `CommandData::resolved` data map are no longer cloned for the option values during deserialization. But the resolved options and values can be accessed via the `CommandData::options()` method. For autocomplete interactions `CommandData::autocomplete()` returns the current autocompleted option + value. BREAKING CHANGES: - `ApplicationCommandInteraction` is now used for application commands and their autocomplete interaction. - The `CommandDataOptionValue`'s variants no longer have the cloned entities from the `CommandData::resolved` data map. See the `CommandData::options` method. - The fields `value`, `kind`, `options` and `focused` of `CommandDataOption` are streamlined into the `CommandDataOptionValue` enum with new variants for subcommands, subcommand groups and autocomplete.
Co-authored-by: Michael Krasnitski <[email protected]>
To simplify the deserialisation implementation for `Event`, it was changed to use serde's native support for `enum` representations that are adjacently tagged (meaning in a text form like JSON, the tag is in one field, the data in the other field). This helped in trimming the lines of code we have to maintain; however, it did break reaction events whose names are prepended `MESSAGE_`, which serde could not account for when renaming, for instance, `ReactionAdd` to SCREAMING_SNAKE_CASE -> `REACTION_ADD`, when it should have been `MESSAGE_REACTION_ADD`. This commit manually renames the reaction events to have `MESSAGE_` at the beginning of their event names.
This converts the hex representation that is used across the API into a much smaller (56 vs 17) type which improves type safety, saves space, and reduces heap allocations (only during a clone).
…delete_message`, and `Webhook::get_message`. (serenity-rs#2465)
This commit reduces the sizes of many integer fields, or converts data to enums when appropriate: - Reduce the size of rate_limit fields - Reduce the size of channel position - Reduce size of role position - Use an enum for `auto_archive_duration` - `DefaultReaction` -> `ForumEmoji` - Swap `AfkTimeout` for enum - Reduce `Sticker::sort_value` to u16 - Reduce size of `min`/`max_values` - Reduce size of `max_uses` and `max_age` - Reduce size of `ActivityParty::size` - Reduce size of `Ready::version` - Reduce `InputText::min/max_length` - Reduce `size`/`width`/`height` -- Discord filesize limits mean we won't hit the size limit, and therefore won't hit height/width limits, plus discord rejects 0 sized files so we can use `NonZero*` - Reduce size of `mention_total_limit` - Reduce size of `RoleSubscriptionData::total_months_subscribed` -- This gives us ~5000 years of role subscription - Fix Change sizes
This alters attribute parse code in `command_attr` to not parse attributes like `#[rustfmt::skip]` as its own, and instead should emit them in the output of the macros.
…Hash` (serenity-rs#2467) This saves an allocation on creation of `ImageHash`.
…erenity-rs#2472) Signed-off-by: Miezhiko <[email protected]>
…ebhook::url`) are None (serenity-rs#2484)
This reverts commit f63e1a4.
…erenity-rs#2496) Untangles dependencies on the `model` and `utils` feature from the `http` feature, allowing compilation without them.
This allows custom statuses to be used. See: discord/discord-api-docs#6345
Currently only supports IDs, might expand to guilds/users/etc as a utility in the future, depending on PR feedback.
Currently running into issues where the compiler seems like it just refuses to use the implementations, and continues suggesting casting to i64. Not sure what the heck is going on, any insight from someone else would be appreciated. |
Accidentally deleted the branch trying to clean up my repo, but yeah I couldn't figure this out. Doesn't seem possible from discussion in the serenity server either, unfortunately. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently only supports IDs, might expand to guilds/users/etc as a shorthand for calling ID. Opened this PR looking for feedback mainly.