diff --git a/src/types/entities/application.rs b/src/types/entities/application.rs index 754c965..f265f21 100644 --- a/src/types/entities/application.rs +++ b/src/types/entities/application.rs @@ -11,6 +11,7 @@ use crate::types::utils::Snowflake; use crate::types::Shared; use crate::types::{Team, User}; +#[allow(unused_imports)] use super::{arc_rwlock_ptr_eq, option_arc_rwlock_ptr_eq}; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -87,13 +88,35 @@ impl PartialEq for Application { && self.discovery_eligibility_flags == other.discovery_eligibility_flags && self.tags == other.tags && self.cover_image == other.cover_image - && option_arc_rwlock_ptr_eq(&self.install_params, &other.install_params) + && compare_install_params(&self.install_params, &other.install_params) && self.terms_of_service_url == other.terms_of_service_url && self.privacy_policy_url == other.privacy_policy_url && self.team == other.team } } +#[cfg(not(tarpaulin_include))] +#[cfg(feature = "sqlx")] +fn compare_install_params( + a: &Option>, + b: &Option>, +) -> bool { + match (a, b) { + (Some(a), Some(b)) => a.encode_to_string() == b.encode_to_string(), + (None, None) => true, + _ => false, + } +} + +#[cfg(not(tarpaulin_include))] +#[cfg(not(feature = "sqlx"))] +fn compare_install_params( + a: &Option>, + b: &Option>, +) -> bool { + option_arc_rwlock_ptr_eq(a, b) +} + impl Default for Application { fn default() -> Self { Self { diff --git a/src/types/entities/audit_log.rs b/src/types/entities/audit_log.rs index ca997a1..b1456b1 100644 --- a/src/types/entities/audit_log.rs +++ b/src/types/entities/audit_log.rs @@ -2,7 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::sync::Arc; +#[allow(unused_imports)] +use super::option_vec_arc_rwlock_ptr_eq; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; @@ -30,39 +31,55 @@ pub struct AuditLogEntry { pub options: Option, pub reason: Option, } - -#[cfg(not(tarpaulin_include))] impl PartialEq for AuditLogEntry { fn eq(&self, other: &Self) -> bool { - let everything_else = self.target_id == other.target_id + self.target_id == other.target_id && self.user_id == other.user_id && self.id == other.id && self.action_type == other.action_type - && self.options == other.options - && self.reason == other.reason; - // Compare the Vec> separately, since Shared doesn't implement PartialEq - match (&self.changes, &other.changes) { - // If both are Some, compare the contents - (Some(self_changes), Some(other_changes)) => { - let mut changes_equal = true; - // Iterate over both Vecs and compare the Arc pointers. If any are different, the - // Vecs are not equal - for (self_change, other_change) in self_changes.iter().zip(other_changes.iter()) { - if !Arc::ptr_eq(self_change, other_change) { - changes_equal = false; - break; - } - } - everything_else && changes_equal - } - // If both are None, they're equal - (None, None) => everything_else, - // If one is Some and the other is None, they're not equal - _ => false, - } + && compare_options(&self.options, &other.options) + && self.reason == other.reason + && compare_changes(&self.changes, &other.changes) } } +#[cfg(not(tarpaulin_include))] +#[cfg(feature = "sqlx")] +fn compare_options( + a: &Option>, + b: &Option>, +) -> bool { + match (a, b) { + (Some(a), Some(b)) => a.encode_to_string() == b.encode_to_string(), + (None, None) => true, + _ => false, + } +} + +#[cfg(not(tarpaulin_include))] +#[cfg(not(feature = "sqlx"))] +fn compare_options(a: &Option, b: &Option) -> bool { + a == b +} + +#[cfg(not(tarpaulin_include))] +#[cfg(feature = "sqlx")] +fn compare_changes( + a: &sqlx::types::Json>>>, + b: &sqlx::types::Json>>>, +) -> bool { + a.encode_to_string() == b.encode_to_string() +} + +#[cfg(not(tarpaulin_include))] +#[cfg(not(feature = "sqlx"))] +fn compare_changes( + a: &Option>>, + b: &Option>>, +) -> bool { + option_vec_arc_rwlock_ptr_eq(a, b) +} + #[derive(Serialize, Deserialize, Debug, Default, Clone)] /// See pub struct AuditLogChange { diff --git a/src/types/entities/channel.rs b/src/types/entities/channel.rs index 00477cd..612111f 100644 --- a/src/types/entities/channel.rs +++ b/src/types/entities/channel.rs @@ -5,6 +5,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Deserializer, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; +use sqlx::types::Json; use std::fmt::{Debug, Formatter}; use std::str::FromStr; @@ -98,6 +99,7 @@ pub struct Channel { } #[cfg(not(tarpaulin_include))] +#[allow(clippy::nonminimal_bool)] impl PartialEq for Channel { fn eq(&self, other: &Self) -> bool { self.application_id == other.application_id @@ -128,7 +130,7 @@ impl PartialEq for Channel { && self.nsfw == other.nsfw && self.owner_id == other.owner_id && self.parent_id == other.parent_id - && option_vec_arc_rwlock_ptr_eq( + && compare_permission_overwrites( &self.permission_overwrites, &other.permission_overwrites, ) @@ -145,6 +147,28 @@ impl PartialEq for Channel { } } +#[cfg(not(tarpaulin_include))] +#[cfg(feature = "sqlx")] +fn compare_permission_overwrites( + a: &Option>>, + b: &Option>>, +) -> bool { + match (a, b) { + (Some(a), Some(b)) => a.encode_to_string() == b.encode_to_string(), + (None, None) => true, + _ => false, + } +} + +#[cfg(not(tarpaulin_include))] +#[cfg(not(feature = "sqlx"))] +fn compare_permission_overrides( + a: &Option>>, + b: &Option>>, +) -> bool { + option_vec_arc_rwlock_ptr_eq(a, b) +} + #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] /// A tag that can be applied to a thread in a [ChannelType::GuildForum] or [ChannelType::GuildMedia] channel. /// diff --git a/src/types/entities/emoji.rs b/src/types/entities/emoji.rs index 55ebb84..82f3e37 100644 --- a/src/types/entities/emoji.rs +++ b/src/types/entities/emoji.rs @@ -45,6 +45,7 @@ pub struct Emoji { } #[cfg(not(tarpaulin_include))] +#[allow(clippy::nonminimal_bool)] impl PartialEq for Emoji { fn eq(&self, other: &Self) -> bool { self.id == other.id @@ -62,7 +63,7 @@ impl PartialEq for Emoji { impl From for Emoji { fn from(value: PartialEmoji) -> Self { Self { - id: value.id.unwrap_or_default(), // TODO: this should be handled differently + id: value.id.unwrap_or_default(), // TODO: Make this method an impl to TryFrom<> instead name: Some(value.name), roles: None, user: None,