Skip to content

Commit

Permalink
Replace a serde::Serialize derive with a simpler manual serialize (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored Oct 18, 2024
1 parent 7cb10ad commit 4c840da
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/model/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod reaction;
use std::fmt;

use serde::de::{Error as DeError, Unexpected};
use serde::ser::SerializeMap as _;

pub use self::attachment::*;
pub use self::channel_id::*;
Expand Down Expand Up @@ -497,25 +498,27 @@ pub enum ForumEmoji {
Name(String),
}

#[derive(Serialize, Deserialize)]
#[derive(Deserialize)]
struct RawForumEmoji {
emoji_id: Option<EmojiId>,
emoji_name: Option<String>,
}

impl serde::Serialize for ForumEmoji {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(Some(2))?;
match self {
Self::Id(id) => RawForumEmoji {
emoji_id: Some(*id),
emoji_name: None,
Self::Id(id) => {
map.serialize_entry("emoji_id", id)?;
map.serialize_entry("emoji_name", &None::<()>)?;
},
Self::Name(name) => RawForumEmoji {
emoji_id: None,
emoji_name: Some(name.clone()),
Self::Name(name) => {
map.serialize_entry("emoji_id", &None::<()>)?;
map.serialize_entry("emoji_name", name)?;
},
}
.serialize(serializer)
};

map.end()
}
}

Expand Down

0 comments on commit 4c840da

Please sign in to comment.