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;