identifiers: Add manual Clone impl for owned ID types
… to get rid of unnecessary bounds.
This commit is contained in:
		
							parent
							
								
									a5c3af4a9a
								
							
						
					
					
						commit
						f6c74fa23a
					
				| @ -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 { | ||||
|                 <str as std::fmt::Debug>::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<std::cmp::Ordering> { | ||||
|                 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<H>(&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<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||||
|             where | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user