From d7c640ceb83416f96245ee5bddd4c63bd19b4e98 Mon Sep 17 00:00:00 2001 From: Gnome! <45660393+GnomedDev@users.noreply.github.com> Date: Sun, 12 Jun 2022 11:37:23 +0200 Subject: [PATCH] Rework manual deserialization implementations (#1938, #1951) --- src/model/application/component.rs | 46 +-- .../interaction/application_command.rs | 213 ++---------- .../application/interaction/autocomplete.rs | 193 +++-------- .../interaction/message_component.rs | 133 +------ src/model/application/interaction/mod.rs | 79 +++-- src/model/application/interaction/modal.rs | 130 +------ src/model/channel/mod.rs | 37 +- src/model/channel/reaction.rs | 47 +-- src/model/event.rs | 21 +- src/model/guild/mod.rs | 325 +----------------- src/model/guild/partial_guild.rs | 251 +++----------- src/model/permissions.rs | 28 +- src/model/utils.rs | 11 + 13 files changed, 289 insertions(+), 1225 deletions(-) diff --git a/src/model/application/component.rs b/src/model/application/component.rs index 49225611134..51033ef78c6 100644 --- a/src/model/application/component.rs +++ b/src/model/application/component.rs @@ -1,8 +1,10 @@ use serde::de::{Deserialize, Deserializer, Error as DeError}; use serde::ser::{Serialize, Serializer}; -use crate::json::{from_value, JsonMap, Value}; +use crate::internal::prelude::*; +use crate::json::from_value; use crate::model::channel::ReactionType; +use crate::model::utils::deserialize_val; /// The type of a component #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] @@ -44,39 +46,27 @@ pub enum ActionRowComponent { } impl<'de> Deserialize<'de> for ActionRowComponent { - fn deserialize>(deserializer: D) -> Result { - let map = JsonMap::deserialize(deserializer)?; - - let kind = map - .get("type") - .ok_or_else(|| DeError::custom("expected type")) - .and_then(ComponentType::deserialize) - .map_err(DeError::custom)?; - - match kind { - ComponentType::Button => from_value::