Skip to content

Commit

Permalink
Use serde instead of json! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Jul 22, 2024
1 parent cd03cc9 commit a9828f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
30 changes: 20 additions & 10 deletions src/client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::gateway::ActivityData;
#[cfg(feature = "gateway")]
use crate::gateway::{ShardMessenger, ShardRunner};
use crate::http::Http;
use crate::json::json;
use crate::model::prelude::*;

/// The context is a general utility struct provided on event dispatches, which helps with dealing
Expand Down Expand Up @@ -335,12 +334,18 @@ impl Context {
/// See [`Guild::create_emoji`] for information about name and filesize requirements. This
/// method will error if said requirements are not met.
pub async fn create_application_emoji(&self, name: &str, image: &str) -> Result<Emoji> {
let map = json!({
"name": name,
"image": image,
});
#[derive(serde::Serialize)]
struct CreateEmoji<'a> {
name: &'a str,
image: &'a str,
}

let body = CreateEmoji {
name,
image,
};

self.http.create_application_emoji(&map).await
self.http.create_application_emoji(&body).await
}

/// Changes the name of an application emoji.
Expand All @@ -349,11 +354,16 @@ impl Context {
///
/// Returns an error if the emoji does not exist.
pub async fn edit_application_emoji(&self, emoji_id: EmojiId, name: &str) -> Result<Emoji> {
let map = json!({
"name": name,
});
#[derive(serde::Serialize)]
struct EditEmoji<'a> {
name: &'a str,
}

let body = EditEmoji {
name,
};

self.http.edit_application_emoji(emoji_id, &map).await
self.http.edit_application_emoji(emoji_id, &body).await
}

/// Deletes an application emoji.
Expand Down
8 changes: 6 additions & 2 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl Http {
/// See [`Context::create_application_emoji`] for required fields.
///
/// [`Context::create_application_emoji`]: crate::client::Context::create_application_emoji
pub async fn create_application_emoji(&self, map: &Value) -> Result<Emoji> {
pub async fn create_application_emoji(&self, map: &impl serde::Serialize) -> Result<Emoji> {
self.fire(Request {
body: Some(to_vec(map)?),
multipart: None,
Expand Down Expand Up @@ -1649,7 +1649,11 @@ impl Http {
/// See [`Context::edit_application_emoji`] for required fields.
///
/// [`Context::edit_application_emoji`]: crate::client::Context::edit_application_emoji
pub async fn edit_application_emoji(&self, emoji_id: EmojiId, map: &Value) -> Result<Emoji> {
pub async fn edit_application_emoji(
&self,
emoji_id: EmojiId,
map: &impl serde::Serialize,
) -> Result<Emoji> {
self.fire(Request {
body: Some(to_vec(map)?),
multipart: None,
Expand Down

0 comments on commit a9828f7

Please sign in to comment.