Skip to content
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
wants to merge 306 commits into from
Closed

Conversation

tazz4843
Copy link
Contributor

Currently only supports IDs, might expand to guilds/users/etc as a shorthand for calling ID. Opened this PR looking for feedback mainly.

GnomedDev and others added 30 commits May 30, 2023 19:42
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)`.
Before `ShardInfo`:
`[serenity::gateway::shard]: [Shard [15, 33]] ...`

Currently:
`[serenity::gateway::shard]: [Shard ShardInfo { id: 15, total: 33 }] ...`

After:
`[serenity::gateway::shard]: [ShardInfo { id: 15, total: 33 }] ...`
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.
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.
…rs#2019)"

This reverts commit de05e5b because it
broke shard code to the point where it just crashes, preventing from
even a simple ping-pong bot from running.
GnomedDev and others added 20 commits June 12, 2023 20:45
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).
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#2496)

Untangles dependencies on the `model` and `utils` feature from the
`http` feature, allowing compilation without them.
Currently only supports IDs,
might expand to guilds/users/etc as a utility in the future,
depending on PR feedback.
@github-actions github-actions bot added the model Related to the `model` module. label Aug 16, 2023
@tazz4843
Copy link
Contributor Author

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.

@tazz4843
Copy link
Contributor Author

tazz4843 commented Oct 7, 2023

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
Labels
model Related to the `model` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.