From 5d8f6748e602146416012d6e34a0600b4bbd540f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Apr 2022 11:03:55 +0200 Subject: [PATCH] identifiers: Add extra PartialEq implementations for owned ID types --- crates/ruma-macros/src/identifiers.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/ruma-macros/src/identifiers.rs b/crates/ruma-macros/src/identifiers.rs index 69d6a18a..06d03be7 100644 --- a/crates/ruma-macros/src/identifiers.rs +++ b/crates/ruma-macros/src/identifiers.rs @@ -282,6 +282,30 @@ fn expand_owned_id(id: &Ident, owned: &Ident) -> TokenStream { #partial_eq_string + impl PartialEq<#id> for #owned { + fn eq(&self, other: &#id) -> bool { + AsRef::<#id>::as_ref(self) == other + } + } + + impl PartialEq<#owned> for #id { + fn eq(&self, other: &#owned) -> bool { + self == AsRef::<#id>::as_ref(other) + } + } + + impl PartialEq<&#id> for #owned { + fn eq(&self, other: &&#id) -> bool { + AsRef::<#id>::as_ref(self) == *other + } + } + + impl PartialEq<#owned> for &#id { + fn eq(&self, other: &#owned) -> bool { + *self == AsRef::<#id>::as_ref(other) + } + } + impl PartialEq> for #owned { fn eq(&self, other: &Box<#id>) -> bool { AsRef::<#id>::as_ref(self) == AsRef::<#id>::as_ref(other)