Compare commits
No commits in common. "76146b0e8c4a4936bdcf79d02be902d2752033dc" and "491cd255de93b1608c3061b436a882908594b0e0" have entirely different histories.
76146b0e8c
...
491cd255de
|
@ -11,7 +11,6 @@ use crate::types::utils::Snowflake;
|
||||||
use crate::types::Shared;
|
use crate::types::Shared;
|
||||||
use crate::types::{Team, User};
|
use crate::types::{Team, User};
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
use super::{arc_rwlock_ptr_eq, option_arc_rwlock_ptr_eq};
|
use super::{arc_rwlock_ptr_eq, option_arc_rwlock_ptr_eq};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -88,35 +87,13 @@ impl PartialEq for Application {
|
||||||
&& self.discovery_eligibility_flags == other.discovery_eligibility_flags
|
&& self.discovery_eligibility_flags == other.discovery_eligibility_flags
|
||||||
&& self.tags == other.tags
|
&& self.tags == other.tags
|
||||||
&& self.cover_image == other.cover_image
|
&& self.cover_image == other.cover_image
|
||||||
&& compare_install_params(&self.install_params, &other.install_params)
|
&& option_arc_rwlock_ptr_eq(&self.install_params, &other.install_params)
|
||||||
&& self.terms_of_service_url == other.terms_of_service_url
|
&& self.terms_of_service_url == other.terms_of_service_url
|
||||||
&& self.privacy_policy_url == other.privacy_policy_url
|
&& self.privacy_policy_url == other.privacy_policy_url
|
||||||
&& self.team == other.team
|
&& self.team == other.team
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
#[cfg(feature = "sqlx")]
|
|
||||||
fn compare_install_params(
|
|
||||||
a: &Option<sqlx::types::Json<InstallParams>>,
|
|
||||||
b: &Option<sqlx::types::Json<InstallParams>>,
|
|
||||||
) -> 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<Shared<InstallParams>>,
|
|
||||||
b: &Option<Shared<InstallParams>>,
|
|
||||||
) -> bool {
|
|
||||||
option_arc_rwlock_ptr_eq(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Application {
|
impl Default for Application {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
use std::sync::Arc;
|
||||||
use super::option_vec_arc_rwlock_ptr_eq;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
@ -32,55 +31,38 @@ pub struct AuditLogEntry {
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
impl PartialEq for AuditLogEntry {
|
impl PartialEq for AuditLogEntry {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.target_id == other.target_id
|
let everything_else = self.target_id == other.target_id
|
||||||
&& self.user_id == other.user_id
|
&& self.user_id == other.user_id
|
||||||
&& self.id == other.id
|
&& self.id == other.id
|
||||||
&& self.action_type == other.action_type
|
&& self.action_type == other.action_type
|
||||||
&& compare_options(&self.options, &other.options)
|
&& self.options == other.options
|
||||||
&& self.reason == other.reason
|
&& self.reason == other.reason;
|
||||||
&& compare_changes(&self.changes, &other.changes)
|
// Compare the Vec<Shared<AuditLogChange>> separately, since Shared<T> 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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
#[cfg(feature = "sqlx")]
|
|
||||||
fn compare_options(
|
|
||||||
a: &Option<sqlx::types::Json<AuditEntryInfo>>,
|
|
||||||
b: &Option<sqlx::types::Json<AuditEntryInfo>>,
|
|
||||||
) -> 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<AuditEntryInfo>, b: &Option<AuditEntryInfo>) -> bool {
|
|
||||||
a == b
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
#[cfg(feature = "sqlx")]
|
|
||||||
fn compare_changes(
|
|
||||||
a: &sqlx::types::Json<Option<Vec<Shared<AuditLogChange>>>>,
|
|
||||||
b: &sqlx::types::Json<Option<Vec<Shared<AuditLogChange>>>>,
|
|
||||||
) -> bool {
|
|
||||||
a.encode_to_string() == b.encode_to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
#[cfg(not(feature = "sqlx"))]
|
|
||||||
fn compare_changes(
|
|
||||||
a: &Option<Vec<Shared<AuditLogChange>>>,
|
|
||||||
b: &Option<Vec<Shared<AuditLogChange>>>,
|
|
||||||
) -> bool {
|
|
||||||
option_vec_arc_rwlock_ptr_eq(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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 {
|
||||||
|
|
|
@ -27,9 +27,6 @@ use crate::gateway::Updateable;
|
||||||
use chorus_macros::{observe_option_vec, Composite, Updateable};
|
use chorus_macros::{observe_option_vec, Composite, Updateable};
|
||||||
use serde::de::{Error, Visitor};
|
use serde::de::{Error, Visitor};
|
||||||
|
|
||||||
#[cfg(feature = "sqlx")]
|
|
||||||
use sqlx::types::Json;
|
|
||||||
|
|
||||||
use super::{option_arc_rwlock_ptr_eq, option_vec_arc_rwlock_ptr_eq};
|
use super::{option_arc_rwlock_ptr_eq, option_vec_arc_rwlock_ptr_eq};
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
|
||||||
|
@ -101,7 +98,6 @@ pub struct Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
#[allow(clippy::nonminimal_bool)]
|
|
||||||
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
|
||||||
|
@ -132,7 +128,7 @@ impl PartialEq for Channel {
|
||||||
&& self.nsfw == other.nsfw
|
&& self.nsfw == other.nsfw
|
||||||
&& self.owner_id == other.owner_id
|
&& self.owner_id == other.owner_id
|
||||||
&& self.parent_id == other.parent_id
|
&& self.parent_id == other.parent_id
|
||||||
&& compare_permission_overwrites(
|
&& option_vec_arc_rwlock_ptr_eq(
|
||||||
&self.permission_overwrites,
|
&self.permission_overwrites,
|
||||||
&other.permission_overwrites,
|
&other.permission_overwrites,
|
||||||
)
|
)
|
||||||
|
@ -149,28 +145,6 @@ impl PartialEq for Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
#[cfg(feature = "sqlx")]
|
|
||||||
fn compare_permission_overwrites(
|
|
||||||
a: &Option<Json<Vec<PermissionOverwrite>>>,
|
|
||||||
b: &Option<Json<Vec<PermissionOverwrite>>>,
|
|
||||||
) -> 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_overwrites(
|
|
||||||
a: &Option<Vec<Shared<PermissionOverwrite>>>,
|
|
||||||
b: &Option<Vec<Shared<PermissionOverwrite>>>,
|
|
||||||
) -> bool {
|
|
||||||
option_vec_arc_rwlock_ptr_eq(a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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.
|
||||||
///
|
///
|
||||||
|
|
|
@ -45,7 +45,6 @@ pub struct Emoji {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
#[allow(clippy::nonminimal_bool)]
|
|
||||||
impl PartialEq for Emoji {
|
impl PartialEq for Emoji {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.id == other.id
|
self.id == other.id
|
||||||
|
@ -63,7 +62,7 @@ impl PartialEq for Emoji {
|
||||||
impl From<PartialEmoji> for Emoji {
|
impl From<PartialEmoji> for Emoji {
|
||||||
fn from(value: PartialEmoji) -> Self {
|
fn from(value: PartialEmoji) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: value.id.unwrap_or_default(), // TODO: Make this method an impl to TryFrom<> instead
|
id: value.id.unwrap_or_default(), // TODO: this should be handled differently
|
||||||
name: Some(value.name),
|
name: Some(value.name),
|
||||||
roles: None,
|
roles: None,
|
||||||
user: None,
|
user: None,
|
||||||
|
|
|
@ -142,21 +142,13 @@ impl<T: Sized> IntoShared for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal function to compare two `Shared<T>`s by comparing their pointers.
|
/// Internal function to compare two `Arc<RwLock<T>>`s by comparing their pointers.
|
||||||
#[cfg_attr(not(feature = "client"), allow(unused_variables))]
|
pub(crate) fn arc_rwlock_ptr_eq<T>(a: &Arc<RwLock<T>>, b: &Arc<RwLock<T>>) -> bool {
|
||||||
pub(crate) fn arc_rwlock_ptr_eq<T>(a: &Shared<T>, b: &Shared<T>) -> bool {
|
Arc::ptr_eq(a, b)
|
||||||
#[cfg(feature = "client")]
|
|
||||||
{
|
|
||||||
Shared::ptr_eq(a, b)
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "client"))]
|
|
||||||
{
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal function to compare two `Vec<Shared<T>>`s by comparing their pointers.
|
/// Internal function to compare two `Vec<Arc<RwLock<T>>>`s by comparing their pointers.
|
||||||
pub(crate) fn vec_arc_rwlock_ptr_eq<T>(a: &[Shared<T>], b: &[Shared<T>]) -> bool {
|
pub(crate) fn vec_arc_rwlock_ptr_eq<T>(a: &Vec<Arc<RwLock<T>>>, b: &Vec<Arc<RwLock<T>>>) -> bool {
|
||||||
for (a, b) in a.iter().zip(b.iter()) {
|
for (a, b) in a.iter().zip(b.iter()) {
|
||||||
if !arc_rwlock_ptr_eq(a, b) {
|
if !arc_rwlock_ptr_eq(a, b) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -165,8 +157,11 @@ pub(crate) fn vec_arc_rwlock_ptr_eq<T>(a: &[Shared<T>], b: &[Shared<T>]) -> bool
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal function to compare two `Option<Shared<T>>`s by comparing their pointers.
|
/// Internal function to compare two `Option<Arc<RwLock<T>>>`s by comparing their pointers.
|
||||||
pub(crate) fn option_arc_rwlock_ptr_eq<T>(a: &Option<Shared<T>>, b: &Option<Shared<T>>) -> bool {
|
pub(crate) fn option_arc_rwlock_ptr_eq<T>(
|
||||||
|
a: &Option<Arc<RwLock<T>>>,
|
||||||
|
b: &Option<Arc<RwLock<T>>>,
|
||||||
|
) -> bool {
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
(Some(a), Some(b)) => arc_rwlock_ptr_eq(a, b),
|
(Some(a), Some(b)) => arc_rwlock_ptr_eq(a, b),
|
||||||
(None, None) => true,
|
(None, None) => true,
|
||||||
|
@ -174,10 +169,10 @@ pub(crate) fn option_arc_rwlock_ptr_eq<T>(a: &Option<Shared<T>>, b: &Option<Shar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Internal function to compare two `Option<Vec<Shared<T>>>`s by comparing their pointers.
|
/// Internal function to compare two `Option<Vec<Arc<RwLock<T>>>>`s by comparing their pointers.
|
||||||
pub(crate) fn option_vec_arc_rwlock_ptr_eq<T>(
|
pub(crate) fn option_vec_arc_rwlock_ptr_eq<T>(
|
||||||
a: &Option<Vec<Shared<T>>>,
|
a: &Option<Vec<Arc<RwLock<T>>>>,
|
||||||
b: &Option<Vec<Shared<T>>>,
|
b: &Option<Vec<Arc<RwLock<T>>>>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
(Some(a), Some(b)) => vec_arc_rwlock_ptr_eq(a, b),
|
(Some(a), Some(b)) => vec_arc_rwlock_ptr_eq(a, b),
|
||||||
|
|
Loading…
Reference in New Issue