diff --git a/crates/ruma-macros/src/identifiers.rs b/crates/ruma-macros/src/identifiers.rs index 99f5786d..37e4d292 100644 --- a/crates/ruma-macros/src/identifiers.rs +++ b/crates/ruma-macros/src/identifiers.rs @@ -234,7 +234,6 @@ fn expand_owned_id(input: &ItemStruct) -> TokenStream { /// `RUSTFLAGS` or `.cargo/config.toml` (under `[build]` -> `rustflags = ["..."]`) /// to the following; /// - `ruma_identifiers_storage="Arc"` to use [`Arc`](std::sync::Arc) as a wrapper type. - #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct #owned #impl_generics { #[cfg(not(any(ruma_identifiers_storage = "Arc")))] inner: Box<#id #ty_generics>, @@ -254,6 +253,12 @@ fn expand_owned_id(input: &ItemStruct) -> TokenStream { } } + impl #impl_generics std::clone::Clone for #owned #ty_generics { + fn clone(&self) -> Self { + (&*self.inner).into() + } + } + impl #impl_generics std::ops::Deref for #owned #ty_generics { type Target = #id #ty_generics; @@ -297,6 +302,41 @@ fn expand_owned_id(input: &ItemStruct) -> TokenStream { } } + impl #impl_generics std::fmt::Debug for #owned #ty_generics { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + ::fmt(self.as_str(), f) + } + } + + impl #impl_generics std::cmp::PartialEq for #owned #ty_generics { + fn eq(&self, other: &Self) -> bool { + self.as_str() == other.as_str() + } + } + + impl #impl_generics std::cmp::Eq for #owned #ty_generics {} + + impl #impl_generics std::cmp::PartialOrd for #owned #ty_generics { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + } + + impl #impl_generics std::cmp::Ord for #owned #ty_generics { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.as_str().cmp(other.as_str()) + } + } + + impl #impl_generics std::hash::Hash for #owned #ty_generics { + fn hash(&self, state: &mut H) + where + H: std::hash::Hasher, + { + self.as_str().hash(state) + } + } + impl #impl_generics serde::Serialize for #owned #ty_generics { fn serialize(&self, serializer: S) -> Result where