From fe70d158e76541a7c720cc35fb0f393c020f55cf Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 16 Apr 2020 13:53:17 +0200 Subject: [PATCH] Implement string comparison for identifier types --- src/macros.rs | 24 ++++++++++++++++++++++++ src/room_version_id.rs | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index 8289823d..06f32306 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -80,5 +80,29 @@ macro_rules! common_impls { crate::deserialize_id(deserializer, $desc) } } + + impl ::std::cmp::PartialEq for $id { + fn eq(&self, other: &str) -> bool { + self.full_id == other + } + } + + impl ::std::cmp::PartialEq<$id> for str { + fn eq(&self, other: &$id) -> bool { + self == other.full_id + } + } + + impl ::std::cmp::PartialEq<::std::string::String> for $id { + fn eq(&self, other: &::std::string::String) -> bool { + &self.full_id == other + } + } + + impl ::std::cmp::PartialEq<$id> for ::string::String { + fn eq(&self, other: &$id) -> bool { + self == &other.full_id + } + } }; } diff --git a/src/room_version_id.rs b/src/room_version_id.rs index 77de552e..5e8d8d35 100644 --- a/src/room_version_id.rs +++ b/src/room_version_id.rs @@ -215,6 +215,30 @@ impl TryFrom for RoomVersionId { } } +impl PartialEq for RoomVersionId { + fn eq(&self, other: &str) -> bool { + self.as_ref() == other + } +} + +impl PartialEq for str { + fn eq(&self, other: &RoomVersionId) -> bool { + self == other.as_ref() + } +} + +impl PartialEq for RoomVersionId { + fn eq(&self, other: &String) -> bool { + self.as_ref() == other + } +} + +impl PartialEq for String { + fn eq(&self, other: &RoomVersionId) -> bool { + self == other.as_ref() + } +} + #[cfg(test)] mod tests { use std::convert::TryFrom;