Skip to content

Commit c105f46

Browse files
authored
Directly serialize CreateSoundboard (#3399)
We don't need to defer to an intermediate struct to avoid serializing the `audit_log_reason`.
1 parent 0537c89 commit c105f46

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

src/builder/create_soundboard.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ use crate::model::prelude::*;
1010
/// A builder to create a soundboard sound.
1111
///
1212
/// [Discord docs](https://discord.com/developers/docs/resources/soundboard#soundboard-resource)
13-
#[derive(Clone, Debug)]
13+
#[derive(Clone, Debug, Serialize)]
1414
#[must_use]
1515
pub struct CreateSoundboard<'a> {
1616
name: String,
1717
sound: String,
1818
volume: f64,
19+
#[serde(skip_serializing_if = "Option::is_none")]
1920
emoji_id: Option<EmojiId>,
21+
#[serde(skip_serializing_if = "Option::is_none")]
2022
emoji_name: Option<String>,
23+
24+
#[serde(skip)]
2125
audit_log_reason: Option<&'a str>,
2226
}
2327

@@ -106,23 +110,6 @@ impl Builder for CreateSoundboard<'_> {
106110
Permissions::CREATE_GUILD_EXPRESSIONS,
107111
)?;
108112

109-
#[derive(serde::Serialize)]
110-
struct CreateSoundboard {
111-
name: String,
112-
sound: String,
113-
volume: f64,
114-
emoji_id: Option<EmojiId>,
115-
emoji_name: Option<String>,
116-
}
117-
118-
let map = CreateSoundboard {
119-
name: self.name,
120-
sound: self.sound,
121-
volume: self.volume,
122-
emoji_id: self.emoji_id,
123-
emoji_name: self.emoji_name,
124-
};
125-
126-
cache_http.http().create_guild_soundboard(ctx, &map, self.audit_log_reason).await
113+
cache_http.http().create_guild_soundboard(ctx, &self, self.audit_log_reason).await
127114
}
128115
}

0 commit comments

Comments
 (0)