diff --git a/crates/ruma-macros/src/identifiers.rs b/crates/ruma-macros/src/identifiers.rs index 33d8bf10..dafda878 100644 --- a/crates/ruma-macros/src/identifiers.rs +++ b/crates/ruma-macros/src/identifiers.rs @@ -313,6 +313,24 @@ fn expand_owned_id(input: &ItemStruct) -> TokenStream { } } + impl #impl_generics From<#owned_ty> for Box<#id_ty> { + fn from(a: #owned_ty) -> Box<#id_ty> { + #[cfg(not(any(ruma_identifiers_storage = "Arc")))] + { a.inner } + #[cfg(ruma_identifiers_storage = "Arc")] + { a.inner.as_ref().into() } + } + } + + impl #impl_generics From<#owned_ty> for std::sync::Arc<#id_ty> { + fn from(a: #owned_ty) -> std::sync::Arc<#id_ty> { + #[cfg(not(any(ruma_identifiers_storage = "Arc")))] + { a.inner.into() } + #[cfg(ruma_identifiers_storage = "Arc")] + { a.inner } + } + } + impl #impl_generics std::fmt::Display for #owned_ty { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.as_str()) @@ -400,6 +418,18 @@ fn expand_owned_id(input: &ItemStruct) -> TokenStream { AsRef::<#id_ty>::as_ref(self) == AsRef::<#id_ty>::as_ref(other) } } + + impl #impl_generics PartialEq> for #owned_ty { + fn eq(&self, other: &std::sync::Arc<#id_ty>) -> bool { + AsRef::<#id_ty>::as_ref(self) == AsRef::<#id_ty>::as_ref(other) + } + } + + impl #impl_generics PartialEq<#owned_ty> for std::sync::Arc<#id_ty> { + fn eq(&self, other: &#owned_ty) -> bool { + AsRef::<#id_ty>::as_ref(self) == AsRef::<#id_ty>::as_ref(other) + } + } } }