identifiers: Rename from_owned to from_box
This commit is contained in:
		
							parent
							
								
									f658487c50
								
							
						
					
					
						commit
						d5656f3399
					
				| @ -23,7 +23,7 @@ impl ClientSecret { | |||||||
|     #[cfg(feature = "rand")] |     #[cfg(feature = "rand")] | ||||||
|     pub fn new() -> Box<Self> { |     pub fn new() -> Box<Self> { | ||||||
|         let id = uuid::Uuid::new_v4(); |         let id = uuid::Uuid::new_v4(); | ||||||
|         Self::from_owned(id.to_simple().to_string().into_boxed_str()) |         Self::from_box(id.to_simple().to_string().into_boxed_str()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -35,7 +35,7 @@ impl DeviceId { | |||||||
|     /// Generates a random `DeviceId`, suitable for assignment to a new device.
 |     /// Generates a random `DeviceId`, suitable for assignment to a new device.
 | ||||||
|     #[cfg(feature = "rand")] |     #[cfg(feature = "rand")] | ||||||
|     pub fn new() -> Box<Self> { |     pub fn new() -> Box<Self> { | ||||||
|         Self::from_owned(generate_localpart(8)) |         Self::from_box(generate_localpart(8)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -63,7 +63,7 @@ mod tests { | |||||||
|     #[test] |     #[test] | ||||||
|     fn create_device_id_from_box() { |     fn create_device_id_from_box() { | ||||||
|         let box_str: Box<str> = "ijklmnop".into(); |         let box_str: Box<str> = "ijklmnop".into(); | ||||||
|         let device_id: Box<DeviceId> = DeviceId::from_owned(box_str); |         let device_id: Box<DeviceId> = DeviceId::from_box(box_str); | ||||||
|         assert_eq!(device_id.as_str(), "ijklmnop"); |         assert_eq!(device_id.as_str(), "ijklmnop"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ impl DeviceKeyId { | |||||||
|         res.push(':'); |         res.push(':'); | ||||||
|         res.push_str(device_id); |         res.push_str(device_id); | ||||||
| 
 | 
 | ||||||
|         Self::from_owned(res.into()) |         Self::from_box(res.into()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Returns key algorithm of the device key ID.
 |     /// Returns key algorithm of the device key ID.
 | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ impl EventId { | |||||||
|     /// 1 and 2.
 |     /// 1 and 2.
 | ||||||
|     #[cfg(feature = "rand")] |     #[cfg(feature = "rand")] | ||||||
|     pub fn new(server_name: &ServerName) -> Box<Self> { |     pub fn new(server_name: &ServerName) -> Box<Self> { | ||||||
|         Self::from_owned(format!("${}:{}", super::generate_localpart(18), server_name).into()) |         Self::from_box(format!("${}:{}", super::generate_localpart(18), server_name).into()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Returns the event's unique ID.
 |     /// Returns the event's unique ID.
 | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ impl<A, K: ?Sized> KeyId<A, K> { | |||||||
|         res.push(':'); |         res.push(':'); | ||||||
|         res.push_str(key_name); |         res.push_str(key_name); | ||||||
| 
 | 
 | ||||||
|         Self::from_owned(res.into()) |         Self::from_box(res.into()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Returns key algorithm of the key ID.
 |     /// Returns key algorithm of the key ID.
 | ||||||
| @ -63,7 +63,7 @@ impl<A, K: ?Sized> KeyId<A, K> { | |||||||
|         unsafe { std::mem::transmute(s) } |         unsafe { std::mem::transmute(s) } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn from_owned(s: Box<str>) -> Box<Self> { |     fn from_box(s: Box<str>) -> Box<Self> { | ||||||
|         unsafe { Box::from_raw(Box::into_raw(s) as _) } |         unsafe { Box::from_raw(Box::into_raw(s) as _) } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -95,7 +95,7 @@ impl<A, K: ?Sized> ToOwned for KeyId<A, K> { | |||||||
|     type Owned = Box<KeyId<A, K>>; |     type Owned = Box<KeyId<A, K>>; | ||||||
| 
 | 
 | ||||||
|     fn to_owned(&self) -> Self::Owned { |     fn to_owned(&self) -> Self::Owned { | ||||||
|         Self::from_owned(self.1.into()) |         Self::from_box(self.1.into()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -227,7 +227,7 @@ where | |||||||
|     S: AsRef<str> + Into<Box<str>>, |     S: AsRef<str> + Into<Box<str>>, | ||||||
| { | { | ||||||
|     ruma_identifiers_validation::key_id::validate(s.as_ref())?; |     ruma_identifiers_validation::key_id::validate(s.as_ref())?; | ||||||
|     Ok(KeyId::from_owned(s.into())) |     Ok(KeyId::from_box(s.into())) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, A, K: ?Sized> TryFrom<&'a str> for &'a KeyId<A, K> { | impl<'a, A, K: ?Sized> TryFrom<&'a str> for &'a KeyId<A, K> { | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ impl RoomId { | |||||||
|     /// Fails if the given homeserver cannot be parsed as a valid host.
 |     /// Fails if the given homeserver cannot be parsed as a valid host.
 | ||||||
|     #[cfg(feature = "rand")] |     #[cfg(feature = "rand")] | ||||||
|     pub fn new(server_name: &ServerName) -> Box<Self> { |     pub fn new(server_name: &ServerName) -> Box<Self> { | ||||||
|         Self::from_owned(format!("!{}:{}", super::generate_localpart(18), server_name).into()) |         Self::from_box(format!("!{}:{}", super::generate_localpart(18), server_name).into()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Returns the rooms's unique ID.
 |     /// Returns the rooms's unique ID.
 | ||||||
|  | |||||||
| @ -58,8 +58,8 @@ impl RoomOrAliasId { | |||||||
|         let boxed_str = self.into_owned(); |         let boxed_str = self.into_owned(); | ||||||
| 
 | 
 | ||||||
|         match variant { |         match variant { | ||||||
|             Variant::RoomId => either::Either::Left(RoomId::from_owned(boxed_str)), |             Variant::RoomId => either::Either::Left(RoomId::from_box(boxed_str)), | ||||||
|             Variant::RoomAliasId => either::Either::Right(RoomAliasId::from_owned(boxed_str)), |             Variant::RoomAliasId => either::Either::Right(RoomAliasId::from_box(boxed_str)), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -96,13 +96,13 @@ impl<'a> From<&'a RoomAliasId> for &'a RoomOrAliasId { | |||||||
| 
 | 
 | ||||||
| impl From<Box<RoomId>> for Box<RoomOrAliasId> { | impl From<Box<RoomId>> for Box<RoomOrAliasId> { | ||||||
|     fn from(room_id: Box<RoomId>) -> Self { |     fn from(room_id: Box<RoomId>) -> Self { | ||||||
|         RoomOrAliasId::from_owned(room_id.into_owned()) |         RoomOrAliasId::from_box(room_id.into_owned()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl From<Box<RoomAliasId>> for Box<RoomOrAliasId> { | impl From<Box<RoomAliasId>> for Box<RoomOrAliasId> { | ||||||
|     fn from(room_alias_id: Box<RoomAliasId>) -> Self { |     fn from(room_alias_id: Box<RoomAliasId>) -> Self { | ||||||
|         RoomOrAliasId::from_owned(room_alias_id.into_owned()) |         RoomOrAliasId::from_box(room_alias_id.into_owned()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -133,8 +133,8 @@ impl TryFrom<Box<RoomOrAliasId>> for Box<RoomId> { | |||||||
| 
 | 
 | ||||||
|     fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomId>, Box<RoomAliasId>> { |     fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomId>, Box<RoomAliasId>> { | ||||||
|         match id.variant() { |         match id.variant() { | ||||||
|             Variant::RoomId => Ok(RoomId::from_owned(id.into_owned())), |             Variant::RoomId => Ok(RoomId::from_box(id.into_owned())), | ||||||
|             Variant::RoomAliasId => Err(RoomAliasId::from_owned(id.into_owned())), |             Variant::RoomAliasId => Err(RoomAliasId::from_box(id.into_owned())), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -144,8 +144,8 @@ impl TryFrom<Box<RoomOrAliasId>> for Box<RoomAliasId> { | |||||||
| 
 | 
 | ||||||
|     fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomAliasId>, Box<RoomId>> { |     fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomAliasId>, Box<RoomId>> { | ||||||
|         match id.variant() { |         match id.variant() { | ||||||
|             Variant::RoomAliasId => Ok(RoomAliasId::from_owned(id.into_owned())), |             Variant::RoomAliasId => Ok(RoomAliasId::from_box(id.into_owned())), | ||||||
|             Variant::RoomId => Err(RoomId::from_owned(id.into_owned())), |             Variant::RoomId => Err(RoomId::from_box(id.into_owned())), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,6 +20,6 @@ impl TransactionId { | |||||||
|     #[cfg(feature = "rand")] |     #[cfg(feature = "rand")] | ||||||
|     pub fn new() -> Box<Self> { |     pub fn new() -> Box<Self> { | ||||||
|         let id = uuid::Uuid::new_v4(); |         let id = uuid::Uuid::new_v4(); | ||||||
|         Self::from_owned(id.to_simple().to_string().into_boxed_str()) |         Self::from_box(id.to_simple().to_string().into_boxed_str()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ impl UserId { | |||||||
|     /// 12 random ASCII characters.
 |     /// 12 random ASCII characters.
 | ||||||
|     #[cfg(feature = "rand")] |     #[cfg(feature = "rand")] | ||||||
|     pub fn new(server_name: &ServerName) -> Box<Self> { |     pub fn new(server_name: &ServerName) -> Box<Self> { | ||||||
|         Self::from_owned( |         Self::from_box( | ||||||
|             format!("@{}:{}", super::generate_localpart(12).to_lowercase(), server_name).into(), |             format!("@{}:{}", super::generate_localpart(12).to_lowercase(), server_name).into(), | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| @ -48,7 +48,7 @@ impl UserId { | |||||||
|             Self::parse(id) |             Self::parse(id) | ||||||
|         } else { |         } else { | ||||||
|             let _ = localpart_is_fully_conforming(id_str)?; |             let _ = localpart_is_fully_conforming(id_str)?; | ||||||
|             Ok(Self::from_owned(format!("@{}:{}", id_str, server_name).into())) |             Ok(Self::from_box(format!("@{}:{}", id_str, server_name).into())) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -60,7 +60,7 @@ pub fn expand_id_zst(input: ItemStruct) -> syn::Result<TokenStream> { | |||||||
|                 unsafe { std::mem::transmute(s) } |                 unsafe { std::mem::transmute(s) } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             pub(super) fn from_owned(s: Box<str>) -> Box<Self> { |             pub(super) fn from_box(s: Box<str>) -> Box<Self> { | ||||||
|                 unsafe { Box::from_raw(Box::into_raw(s) as _) } |                 unsafe { Box::from_raw(Box::into_raw(s) as _) } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -97,7 +97,7 @@ pub fn expand_id_zst(input: ItemStruct) -> syn::Result<TokenStream> { | |||||||
|             type Owned = Box<#id>; |             type Owned = Box<#id>; | ||||||
| 
 | 
 | ||||||
|             fn to_owned(&self) -> Self::Owned { |             fn to_owned(&self) -> Self::Owned { | ||||||
|                 Self::from_owned(self.0.into()) |                 Self::from_box(self.0.into()) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -121,7 +121,7 @@ pub fn expand_id_zst(input: ItemStruct) -> syn::Result<TokenStream> { | |||||||
| 
 | 
 | ||||||
|         impl From<&#id> for Box<#id> { |         impl From<&#id> for Box<#id> { | ||||||
|             fn from(id: &#id) -> Self { |             fn from(id: &#id) -> Self { | ||||||
|                 #id::from_owned(id.0.into()) |                 #id::from_box(id.0.into()) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -299,7 +299,7 @@ fn expand_checked_impls(id: &Ident, owned: &Ident, validate: Path) -> TokenStrea | |||||||
|                 s: impl AsRef<str> + Into<Box<str>>, |                 s: impl AsRef<str> + Into<Box<str>>, | ||||||
|             ) -> Result<Box<Self>, crate::IdParseError> { |             ) -> Result<Box<Self>, crate::IdParseError> { | ||||||
|                 #validate(s.as_ref())?; |                 #validate(s.as_ref())?; | ||||||
|                 Ok(#id::from_owned(s.into())) |                 Ok(#id::from_box(s.into())) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             #[doc = #parse_rc_docs] |             #[doc = #parse_rc_docs] | ||||||
| @ -396,19 +396,19 @@ fn expand_unchecked_impls(id: &Ident, owned: &Ident) -> TokenStream { | |||||||
| 
 | 
 | ||||||
|         impl From<&str> for Box<#id> { |         impl From<&str> for Box<#id> { | ||||||
|             fn from(s: &str) -> Self { |             fn from(s: &str) -> Self { | ||||||
|                 #id::from_owned(s.into()) |                 #id::from_box(s.into()) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         impl From<Box<str>> for Box<#id> { |         impl From<Box<str>> for Box<#id> { | ||||||
|             fn from(s: Box<str>) -> Self { |             fn from(s: Box<str>) -> Self { | ||||||
|                 #id::from_owned(s) |                 #id::from_box(s) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         impl From<String> for Box<#id> { |         impl From<String> for Box<#id> { | ||||||
|             fn from(s: String) -> Self { |             fn from(s: String) -> Self { | ||||||
|                 #id::from_owned(s.into()) |                 #id::from_box(s.into()) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -423,7 +423,7 @@ fn expand_unchecked_impls(id: &Ident, owned: &Ident) -> TokenStream { | |||||||
|             where |             where | ||||||
|                 D: serde::Deserializer<'de>, |                 D: serde::Deserializer<'de>, | ||||||
|             { |             { | ||||||
|                 Box::<str>::deserialize(deserializer).map(#id::from_owned) |                 Box::<str>::deserialize(deserializer).map(#id::from_box) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -433,7 +433,7 @@ fn expand_unchecked_impls(id: &Ident, owned: &Ident) -> TokenStream { | |||||||
|                 D: serde::Deserializer<'de>, |                 D: serde::Deserializer<'de>, | ||||||
|             { |             { | ||||||
|                 // FIXME: Deserialize inner, convert that
 |                 // FIXME: Deserialize inner, convert that
 | ||||||
|                 Box::<str>::deserialize(deserializer).map(#id::from_owned).map(Into::into) |                 Box::<str>::deserialize(deserializer).map(#id::from_box).map(Into::into) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user