aboutsummaryrefslogtreecommitdiff
path: root/src/model/mod.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-17 11:19:00 -0800
committerAustin Hellyer <[email protected]>2016-11-17 11:19:00 -0800
commitbdc319525396a36c029600a2cd9750e28633a805 (patch)
treea01cf10c4946086fa7f9b36f589d588a2ad7a34a /src/model/mod.rs
parentDecode discriminators as strings (diff)
downloadserenity-bdc319525396a36c029600a2cd9750e28633a805.tar.xz
serenity-bdc319525396a36c029600a2cd9750e28633a805.zip
Allow Id/u64 equality comparisons
This will allow comparing, for example, a `ChannelId` with a `u64` directly, bypassing the need to do something like: ```rust let channel_id = ChannelId(7); assert!(channel_id.0 == 7); // can now be replaced with: assert!(channel_id == 7); ```
Diffstat (limited to 'src/model/mod.rs')
-rw-r--r--src/model/mod.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/model/mod.rs b/src/model/mod.rs
index f00dffb..0b93823 100644
--- a/src/model/mod.rs
+++ b/src/model/mod.rs
@@ -56,7 +56,7 @@ macro_rules! id {
($(#[$attr:meta] $name:ident;)*) => {
$(
#[$attr]
- #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
+ #[derive(Copy, Clone, Debug, Eq, Hash, PartialOrd, Ord)]
pub struct $name(pub u64);
impl $name {
@@ -76,6 +76,18 @@ macro_rules! id {
$name(id_as_u64)
}
}
+
+ impl PartialEq for $name {
+ fn eq(&self, other: &Self) -> bool {
+ self.0 == other.0
+ }
+ }
+
+ impl PartialEq<u64> for $name {
+ fn eq(&self, u: &u64) -> bool {
+ self.0 == *u
+ }
+ }
)*
}
}