Provide alternative implementations for PartialEq for some types when sqlx feature is enabled

This commit is contained in:
bitfl0wer 2024-07-20 16:54:47 +02:00
parent 491cd255de
commit cd0230e64d
No known key found for this signature in database
GPG Key ID: 0ACD574FCF5226CF
3 changed files with 104 additions and 0 deletions

View File

@ -62,6 +62,7 @@ pub struct Application {
} }
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
#[cfg(not(feature = "sqlx"))]
impl PartialEq for Application { impl PartialEq for Application {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.id == other.id self.id == other.id
@ -94,6 +95,44 @@ impl PartialEq for Application {
} }
} }
#[cfg(not(tarpaulin_include))]
#[cfg(feature = "sqlx")]
impl PartialEq for Application {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
&& self.name == other.name
&& self.icon == other.icon
&& self.description == other.description
&& self.summary == other.summary
&& self.r#type == other.r#type
&& self.r#type == other.r#type
&& self.hook == other.hook
&& self.bot_public == other.bot_public
&& self.bot_require_code_grant == other.bot_require_code_grant
&& self.verify_key == other.verify_key
&& arc_rwlock_ptr_eq(&self.owner, &other.owner)
&& self.flags == other.flags
&& self.redirect_uris == other.redirect_uris
&& self.redirect_uris == other.redirect_uris
&& self.rpc_application_state == other.rpc_application_state
&& self.store_application_state == other.store_application_state
&& self.verification_state == other.verification_state
&& self.interactions_endpoint_url == other.interactions_endpoint_url
&& self.integration_public == other.integration_public
&& self.integration_require_code_grant == other.integration_require_code_grant
&& self.discoverability_state == other.discoverability_state
&& self.discovery_eligibility_flags == other.discovery_eligibility_flags
&& self.tags == other.tags
&& self.tags == other.tags
&& self.cover_image == other.cover_image
&& self.install_params == other.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
}
}
impl Default for Application { impl Default for Application {
fn default() -> Self { fn default() -> Self {
Self { Self {

View File

@ -32,6 +32,7 @@ pub struct AuditLogEntry {
} }
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
#[cfg(not(feature = "sqlx"))]
impl PartialEq for AuditLogEntry { impl PartialEq for AuditLogEntry {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
let everything_else = self.target_id == other.target_id let everything_else = self.target_id == other.target_id
@ -63,6 +64,22 @@ impl PartialEq for AuditLogEntry {
} }
} }
#[cfg(not(tarpaulin_include))]
#[cfg(feature = "sqlx")]
impl PartialEq for AuditLogEntry {
fn eq(&self, other: &Self) -> bool {
self.target_id == other.target_id
// Serialize the `Vec<Shared<AuditLogChange>>` to a string and compare them
&& self.changes.encode_to_string() == other.changes.encode_to_string()
&& self.user_id == other.user_id
&& self.id == other.id
&& self.action_type == other.action_type
&& self.options == other.options
&& self.options == other.options
&& self.reason == other.reason
}
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)] #[derive(Serialize, Deserialize, Debug, Default, Clone)]
/// See <https://discord.com/developers/docs/resources/audit-log#audit-log-change-object> /// See <https://discord.com/developers/docs/resources/audit-log#audit-log-change-object>
pub struct AuditLogChange { pub struct AuditLogChange {

View File

@ -98,6 +98,7 @@ pub struct Channel {
} }
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
#[cfg(not(feature = "sqlx"))]
impl PartialEq for Channel { impl PartialEq for Channel {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.application_id == other.application_id self.application_id == other.application_id
@ -145,6 +146,53 @@ impl PartialEq for Channel {
} }
} }
#[cfg(not(tarpaulin_include))]
#[cfg(feature = "sqlx")]
impl PartialEq for Channel {
#[allow(clippy::nonminimal_bool)]
fn eq(&self, other: &Self) -> bool {
self.application_id == other.application_id
&& self.applied_tags == other.applied_tags
&& self.applied_tags == other.applied_tags
&& self.available_tags == other.available_tags
&& self.available_tags == other.available_tags
&& self.bitrate == other.bitrate
&& self.channel_type == other.channel_type
&& self.created_at == other.created_at
&& self.default_auto_archive_duration == other.default_auto_archive_duration
&& self.default_forum_layout == other.default_forum_layout
&& self.default_reaction_emoji == other.default_reaction_emoji
&& self.default_reaction_emoji == other.default_reaction_emoji
&& self.default_sort_order == other.default_sort_order
&& self.default_thread_rate_limit_per_user == other.default_thread_rate_limit_per_user
&& self.flags == other.flags
&& self.guild_id == other.guild_id
&& self.icon == other.icon
&& self.id == other.id
&& self.last_message_id == other.last_message_id
&& self.last_pin_timestamp == other.last_pin_timestamp
&& self.managed == other.managed
&& self.member == other.member
&& self.member_count == other.member_count
&& self.message_count == other.message_count
&& self.name == other.name
&& self.nsfw == other.nsfw
&& self.owner_id == other.owner_id
&& self.parent_id == other.parent_id
&& self.permission_overwrites == other.permission_overwrites
&& self.permissions == other.permissions
&& self.position == other.position
&& self.rate_limit_per_user == other.rate_limit_per_user
&& option_vec_arc_rwlock_ptr_eq(&self.recipients, &other.recipients)
&& self.rtc_region == other.rtc_region
&& self.thread_metadata == other.thread_metadata
&& self.topic == other.topic
&& self.total_message_sent == other.total_message_sent
&& self.user_limit == other.user_limit
&& self.video_quality_mode == other.video_quality_mode
}
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[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. /// A tag that can be applied to a thread in a [ChannelType::GuildForum] or [ChannelType::GuildMedia] channel.
/// ///