Skip to content

Commit 276901f

Browse files
authored
Bump the discriminant of audit_log::Action to u16 (#3062)
Values are getting quite close to the u8 limit (193), so let's preemptively bump this to avoid future breaking changes.
1 parent 705e1bb commit 276901f

File tree

1 file changed

+21
-37
lines changed
  • src/model/guild/audit_log

1 file changed

+21
-37
lines changed

src/model/guild/audit_log/mod.rs

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,36 @@ pub enum Action {
3535
AutoMod(AutoModAction),
3636
CreatorMonetization(CreatorMonetizationAction),
3737
VoiceChannelStatus(VoiceChannelStatusAction),
38-
Unknown(u8),
38+
Unknown(u16),
3939
}
4040

4141
impl Action {
4242
#[must_use]
43-
pub const fn num(self) -> u8 {
43+
pub const fn num(self) -> u16 {
4444
match self {
4545
Self::GuildUpdate => 1,
46-
Self::Channel(x) => x as u8,
47-
Self::ChannelOverwrite(x) => x as u8,
48-
Self::Member(x) => x as u8,
49-
Self::Role(x) => x as u8,
50-
Self::Invite(x) => x as u8,
51-
Self::Webhook(x) => x as u8,
52-
Self::Emoji(x) => x as u8,
53-
Self::Message(x) => x as u8,
54-
Self::Integration(x) => x as u8,
55-
Self::StageInstance(x) => x as u8,
56-
Self::Sticker(x) => x as u8,
57-
Self::ScheduledEvent(x) => x as u8,
58-
Self::Thread(x) => x as u8,
59-
Self::AutoMod(x) => x as u8,
60-
Self::CreatorMonetization(x) => x as u8,
61-
Self::VoiceChannelStatus(x) => x as u8,
46+
Self::Channel(x) => x as u16,
47+
Self::ChannelOverwrite(x) => x as u16,
48+
Self::Member(x) => x as u16,
49+
Self::Role(x) => x as u16,
50+
Self::Invite(x) => x as u16,
51+
Self::Webhook(x) => x as u16,
52+
Self::Emoji(x) => x as u16,
53+
Self::Message(x) => x as u16,
54+
Self::Integration(x) => x as u16,
55+
Self::StageInstance(x) => x as u16,
56+
Self::Sticker(x) => x as u16,
57+
Self::ScheduledEvent(x) => x as u16,
58+
Self::Thread(x) => x as u16,
59+
Self::AutoMod(x) => x as u16,
60+
Self::CreatorMonetization(x) => x as u16,
61+
Self::VoiceChannelStatus(x) => x as u16,
6262
Self::Unknown(x) => x,
6363
}
6464
}
6565

6666
#[must_use]
67-
pub fn from_value(value: u8) -> Action {
67+
pub fn from_value(value: u16) -> Action {
6868
match value {
6969
1 => Action::GuildUpdate,
7070
10 => Action::Channel(ChannelAction::Create),
@@ -131,22 +131,21 @@ impl Action {
131131
// Manual impl needed to emulate integer enum tags
132132
impl<'de> Deserialize<'de> for Action {
133133
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> {
134-
let value = u8::deserialize(deserializer)?;
134+
let value = u16::deserialize(deserializer)?;
135135
Ok(Action::from_value(value))
136136
}
137137
}
138138

139139
impl Serialize for Action {
140140
fn serialize<S: Serializer>(&self, serializer: S) -> StdResult<S::Ok, S::Error> {
141-
serializer.serialize_u8(self.num())
141+
serializer.serialize_u16(self.num())
142142
}
143143
}
144144

145145
/// [Discord docs](https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events).
146146
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
147147
#[derive(Clone, Copy, Debug)]
148148
#[non_exhaustive]
149-
#[repr(u8)]
150149
pub enum ChannelAction {
151150
Create = 10,
152151
Update = 11,
@@ -157,7 +156,6 @@ pub enum ChannelAction {
157156
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
158157
#[derive(Clone, Copy, Debug)]
159158
#[non_exhaustive]
160-
#[repr(u8)]
161159
pub enum ChannelOverwriteAction {
162160
Create = 13,
163161
Update = 14,
@@ -168,7 +166,6 @@ pub enum ChannelOverwriteAction {
168166
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
169167
#[derive(Clone, Copy, Debug)]
170168
#[non_exhaustive]
171-
#[repr(u8)]
172169
pub enum MemberAction {
173170
Kick = 20,
174171
Prune = 21,
@@ -185,7 +182,6 @@ pub enum MemberAction {
185182
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
186183
#[derive(Clone, Copy, Debug)]
187184
#[non_exhaustive]
188-
#[repr(u8)]
189185
pub enum RoleAction {
190186
Create = 30,
191187
Update = 31,
@@ -196,7 +192,6 @@ pub enum RoleAction {
196192
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
197193
#[derive(Clone, Copy, Debug)]
198194
#[non_exhaustive]
199-
#[repr(u8)]
200195
pub enum InviteAction {
201196
Create = 40,
202197
Update = 41,
@@ -207,7 +202,6 @@ pub enum InviteAction {
207202
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
208203
#[derive(Clone, Copy, Debug)]
209204
#[non_exhaustive]
210-
#[repr(u8)]
211205
pub enum WebhookAction {
212206
Create = 50,
213207
Update = 51,
@@ -218,7 +212,6 @@ pub enum WebhookAction {
218212
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
219213
#[derive(Clone, Copy, Debug)]
220214
#[non_exhaustive]
221-
#[repr(u8)]
222215
pub enum EmojiAction {
223216
Create = 60,
224217
Update = 61,
@@ -229,7 +222,6 @@ pub enum EmojiAction {
229222
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
230223
#[derive(Clone, Copy, Debug)]
231224
#[non_exhaustive]
232-
#[repr(u8)]
233225
pub enum MessageAction {
234226
Delete = 72,
235227
BulkDelete = 73,
@@ -241,7 +233,6 @@ pub enum MessageAction {
241233
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
242234
#[derive(Clone, Copy, Debug)]
243235
#[non_exhaustive]
244-
#[repr(u8)]
245236
pub enum IntegrationAction {
246237
Create = 80,
247238
Update = 81,
@@ -252,7 +243,6 @@ pub enum IntegrationAction {
252243
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
253244
#[derive(Clone, Copy, Debug)]
254245
#[non_exhaustive]
255-
#[repr(u8)]
256246
pub enum StageInstanceAction {
257247
Create = 83,
258248
Update = 84,
@@ -263,7 +253,6 @@ pub enum StageInstanceAction {
263253
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
264254
#[derive(Clone, Copy, Debug)]
265255
#[non_exhaustive]
266-
#[repr(u8)]
267256
pub enum StickerAction {
268257
Create = 90,
269258
Update = 91,
@@ -274,7 +263,6 @@ pub enum StickerAction {
274263
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
275264
#[derive(Clone, Copy, Debug)]
276265
#[non_exhaustive]
277-
#[repr(u8)]
278266
pub enum ScheduledEventAction {
279267
Create = 100,
280268
Update = 101,
@@ -285,7 +273,6 @@ pub enum ScheduledEventAction {
285273
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
286274
#[derive(Clone, Copy, Debug)]
287275
#[non_exhaustive]
288-
#[repr(u8)]
289276
pub enum ThreadAction {
290277
Create = 110,
291278
Update = 111,
@@ -296,7 +283,6 @@ pub enum ThreadAction {
296283
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
297284
#[derive(Copy, Clone, Debug)]
298285
#[non_exhaustive]
299-
#[repr(u8)]
300286
pub enum AutoModAction {
301287
RuleCreate = 140,
302288
RuleUpdate = 141,
@@ -310,7 +296,6 @@ pub enum AutoModAction {
310296
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
311297
#[derive(Copy, Clone, Debug)]
312298
#[non_exhaustive]
313-
#[repr(u8)]
314299
pub enum CreatorMonetizationAction {
315300
RequestCreated = 150,
316301
TermsAccepted = 151,
@@ -320,7 +305,6 @@ pub enum CreatorMonetizationAction {
320305
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
321306
#[derive(Copy, Clone, Debug)]
322307
#[non_exhaustive]
323-
#[repr(u8)]
324308
pub enum VoiceChannelStatusAction {
325309
StatusUpdate = 192,
326310
StatusDelete = 193,

0 commit comments

Comments
 (0)