identifiers: Add Into Box & Arc, and PartialEq Arc (#1235)

* Add Into Box & Arc, and PartialEq Arc

* change into to from

* Apply suggestions from code review

Co-authored-by: Jonas Platte <jplatte@element.io>

Co-authored-by: Jonas Platte <jplatte@element.io>
This commit is contained in:
Jonathan de Jong 2022-07-12 10:44:02 +02:00 committed by GitHub
parent e2d0e4cf20
commit 8f8937b29e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<std::sync::Arc<#id_ty>> 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)
}
}
}
}