From 76c1ea2323abffdc2030e5b20b5693e028266bed Mon Sep 17 00:00:00 2001 From: Gnome! Date: Thu, 28 Dec 2023 16:17:26 +0000 Subject: [PATCH] Use `FixedArray` and `FixedString` in model enums (#2675) Simply missed these when finding and replacing. --- src/model/application/command_interaction.rs | 8 ++-- src/model/channel/message.rs | 2 +- src/model/guild/audit_log/change.rs | 44 ++++++++++---------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/model/application/command_interaction.rs b/src/model/application/command_interaction.rs index 423cec1138a..e8e2d908f66 100644 --- a/src/model/application/command_interaction.rs +++ b/src/model/application/command_interaction.rs @@ -339,10 +339,10 @@ impl CommandData { for opt in opts { let value = match &opt.value { CommandDataOptionValue::SubCommand(opts) => { - ResolvedValue::SubCommand(resolve_options(opts, resolved)) + ResolvedValue::SubCommand(resolve_options(opts, resolved).into()) }, CommandDataOptionValue::SubCommandGroup(opts) => { - ResolvedValue::SubCommandGroup(resolve_options(opts, resolved)) + ResolvedValue::SubCommandGroup(resolve_options(opts, resolved).into()) }, CommandDataOptionValue::Autocomplete { kind, @@ -447,8 +447,8 @@ pub enum ResolvedValue<'a> { Integer(i64), Number(f64), String(&'a str), - SubCommand(Vec>), - SubCommandGroup(Vec>), + SubCommand(FixedArray>), + SubCommandGroup(FixedArray>), Attachment(&'a Attachment), Channel(&'a PartialChannel), Role(&'a Role), diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index 2c30ca97075..c3793eee303 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -1114,7 +1114,7 @@ impl MessageId { #[derive(Clone, Debug, Serialize)] #[serde(untagged)] pub enum Nonce { - String(String), + String(FixedString), Number(u64), } diff --git a/src/model/guild/audit_log/change.rs b/src/model/guild/audit_log/change.rs index ed5037b344d..d7d59a30ef1 100644 --- a/src/model/guild/audit_log/change.rs +++ b/src/model/guild/audit_log/change.rs @@ -29,7 +29,7 @@ pub struct AffectedRole { #[non_exhaustive] pub enum EntityType { Int(u64), - Str(String), + Str(FixedString), } impl<'de> serde::Deserialize<'de> for EntityType { @@ -71,20 +71,20 @@ macro_rules! generate_change { RolesAdded { #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "old_value")] - old: Option>, + old: Option>, #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "new_value")] - new: Option>, + new: Option>, }, /// Role was removed to a member. #[serde(rename = "$remove")] RolesRemove { #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "old_value")] - old: Option>, + old: Option>, #[serde(skip_serializing_if = "Option::is_none")] #[serde(rename = "new_value")] - new: Option>, + new: Option>, }, /// Unknown key was changed. @@ -119,7 +119,7 @@ macro_rules! generate_change { } generate_change! { - "actions" => Actions(Vec), + "actions" => Actions(FixedArray), /// AFK channel was changed. "afk_channel_id" => AfkChannelId(ChannelId), /// AFK timeout duration was changed. @@ -130,7 +130,7 @@ generate_change! { "application_id" => ApplicationId(ApplicationId), /// Thread is now archived/unarchived. "archived" => Archived(bool), - "asset" => Asset(String), + "asset" => Asset(FixedString), /// Auto archive duration of a thread was changed. "auto_archive_duration" => AutoArchiveDuration(u16), /// Availability of a sticker was changed. @@ -144,7 +144,7 @@ generate_change! { /// Channel for invite code or guild scheduled event was changed. "channel_id" => ChannelId(ChannelId), /// Invite code was changed. - "code" => Code(String), + "code" => Code(FixedString), /// Role color was changed. "color" => Color(u32), /// Member timeout state was changed. @@ -158,7 +158,7 @@ generate_change! { /// Permission on a text or voice channel was denied for a role. "deny" => Deny(Permissions), /// Description for guild, sticker, or guild scheduled event was changed. - "description" => Description(String), + "description" => Description(FixedString), /// Guild's discovery splash was changed. "discovery_splash_hash" => DiscoverySplashHash(ImageHash), "enabled" => Enabled(bool), @@ -167,8 +167,8 @@ generate_change! { /// Entity type of guild scheduled event was changed. "entity_type" => EntityType(u64), "event_type" => EventType(EventType), - "exempt_channels" => ExemptChannels(Vec), - "exempt_roles" => ExemptRoles(Vec), + "exempt_channels" => ExemptChannels(FixedArray), + "exempt_roles" => ExemptRoles(FixedArray), /// Behavior of the expiration of an integration was changed. "expire_behavior" => ExpireBehavior(u64), /// Grace period of the expiration of an integration was changed. @@ -194,7 +194,7 @@ generate_change! { /// ID of the user who created the invite. "inviter_id" => InviterId(UserId), /// Location for a guild scheduled event was changed. - "location" => Location(String), + "location" => Location(FixedString), /// Thread was locked/unlocked. "locked" => Locked(bool), /// How long invite code lasts was changed. @@ -208,21 +208,21 @@ generate_change! { /// User was server muted/unmuted. "mute" => Mute(bool), /// Name of an entity was changed. - "name" => Name(String), + "name" => Name(FixedString), /// Nickname of a member was changed. - "nick" => Nick(String), + "nick" => Nick(FixedString), /// Channel NSFW restriction was changed. "nsfw" => Nsfw(bool), /// Owner of a guild was changed. "owner_id" => OwnerId(UserId), /// Permissions on a channel were changed. - "permission_overwrites" => PermissionOverwrites(Vec), + "permission_overwrites" => PermissionOverwrites(FixedArray), /// Permissions for a role were changed. "permissions" => Permissions(Permissions), /// Channel or role position was changed. "position" => Position(u32), /// Preferred locale of a guild was changed. - "preferred_locale" => PreferredLocale(String), + "preferred_locale" => PreferredLocale(FixedString), /// Privacy level of the stage instance was changed. "privacy_level" => PrivacyLevel(u64), /// Number of days after which inactive and role-unassigned members are kicked was changed. @@ -232,7 +232,7 @@ generate_change! { /// Ratelimit per user in a text channel was changed. "rate_limit_per_user" => RateLimitPerUser(u16), /// Region of a guild was changed. - "region" => Region(String), + "region" => Region(FixedString), /// ID of the rules channel was changed. "rules_channel_id" => RulesChannelId(ChannelId), /// Invite splash page artwork was changed. @@ -242,23 +242,23 @@ generate_change! { /// ID of the system channel was changed. "system_channel_id" => SystemChannelId(ChannelId), /// Related emoji of a sticker was changed. - "tags" => Tags(String), + "tags" => Tags(FixedString), /// Whether an invite is temporary or never expires was changed. "temporary" => Temporary(bool), /// Topic of a text channel or stage instance was changed. - "topic" => Topic(String), + "topic" => Topic(FixedString), "trigger_metadata" => TriggerMetadata(TriggerMetadata), "trigger_type" => TriggerType(TriggerType), /// Type of a created entity. "type" => Type(EntityType), /// Unicode emoji of a role icon was changed. - "unicode_emoji" => UnicodeEmoji(String), + "unicode_emoji" => UnicodeEmoji(FixedString), /// Maximum number of users in a voice channel was changed. "user_limit" => UserLimit(u64), /// Number of uses of an invite was changed. "uses" => Uses(u64), /// Guild invite vanity url was changed. - "vanity_url_code" => VanityUrlCode(String), + "vanity_url_code" => VanityUrlCode(FixedString), /// Required verification level for new members was changed. "verification_level" => VerificationLevel(VerificationLevel), /// Channel of the server widget was changed. @@ -299,7 +299,7 @@ mod tests { fn entity_type_variant() { let value = Change::Type { old: Some(EntityType::Int(123)), - new: Some(EntityType::Str("discord".into())), + new: Some(EntityType::Str("discord".to_string().into())), }; assert_json(&value, json!({"key": "type", "old_value": 123, "new_value": "discord"})); }