diff --git a/src/model/colour.rs b/src/model/colour.rs index de26ed4a58f..172769f9ff7 100644 --- a/src/model/colour.rs +++ b/src/model/colour.rs @@ -66,7 +66,9 @@ /// ``` /// /// [`Role`]: crate::model::guild::Role -#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)] +#[derive( + Clone, Copy, Debug, Default, Eq, Ord, Hash, PartialEq, PartialOrd, Deserialize, Serialize, +)] #[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] pub struct Colour(pub u32); diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index 4bc4645830e..44fbd51015d 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -535,7 +535,7 @@ impl fmt::Display for Member { /// [link](https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object)) #[bool_to_bitflags::bool_to_bitflags] #[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, serde::Deserialize, serde::Serialize)] #[non_exhaustive] pub struct PartialMember { /// Indicator of whether the member can hear in voice channels. diff --git a/src/model/guild/role.rs b/src/model/guild/role.rs index d5a6098e517..c4773f10c09 100644 --- a/src/model/guild/role.rs +++ b/src/model/guild/role.rs @@ -18,7 +18,7 @@ use crate::model::utils::is_false; /// [Discord docs](https://discord.com/developers/docs/topics/permissions#role-object). #[bool_to_bitflags::bool_to_bitflags] #[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] -#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize)] #[non_exhaustive] pub struct Role { /// The Id of the role. Can be used to calculate the role's creation date. @@ -130,7 +130,11 @@ impl fmt::Display for Role { } } -impl Eq for Role {} +impl PartialOrd for Role { + fn partial_cmp(&self, other: &Role) -> Option { + Some(self.cmp(other)) + } +} impl Ord for Role { fn cmp(&self, other: &Role) -> Ordering { @@ -142,18 +146,6 @@ impl Ord for Role { } } -impl PartialEq for Role { - fn eq(&self, other: &Role) -> bool { - self.id == other.id - } -} - -impl PartialOrd for Role { - fn partial_cmp(&self, other: &Role) -> Option { - Some(self.cmp(other)) - } -} - impl From for RoleId { /// Gets the Id of a role. fn from(role: Role) -> RoleId { diff --git a/src/model/misc.rs b/src/model/misc.rs index 8f1a239bd04..ef2d66858b1 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -17,7 +17,7 @@ use crate::utils; /// Hides the implementation detail of ImageHash as an enum. #[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, Hash, PartialEq, Eq)] enum ImageHashInner { Normal { hash: [u8; 16], is_animated: bool }, Clyde, @@ -37,7 +37,7 @@ enum ImageHashInner { /// ``` #[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, Hash, PartialEq, Eq)] pub struct ImageHash(ImageHashInner); impl ImageHash { diff --git a/src/model/user.rs b/src/model/user.rs index 2216fddc1ca..92d45d4c80c 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -223,7 +223,7 @@ impl OnlineStatus { /// additional partial member field documented [here](https://discord.com/developers/docs/topics/gateway-events#message-create). #[bool_to_bitflags::bool_to_bitflags] #[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))] -#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize)] #[non_exhaustive] pub struct User { /// The unique Id of the user. Can be used to calculate the account's creation date. @@ -351,22 +351,6 @@ bitflags! { } } -use std::hash::{Hash, Hasher}; - -impl PartialEq for User { - fn eq(&self, other: &Self) -> bool { - self.id == other.id - } -} - -impl Eq for User {} - -impl Hash for User { - fn hash(&self, hasher: &mut H) { - self.id.hash(hasher); - } -} - #[cfg(feature = "model")] impl User { /// Returns the formatted URL of the user's icon, if one exists.