From d5656f33996488bfd93c00213d5ea7aad11833b7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 14 Apr 2022 11:22:55 +0200 Subject: [PATCH] identifiers: Rename from_owned to from_box --- .../src/identifiers/client_secret.rs | 2 +- .../ruma-common/src/identifiers/device_id.rs | 4 ++-- .../src/identifiers/device_key_id.rs | 2 +- crates/ruma-common/src/identifiers/event_id.rs | 2 +- crates/ruma-common/src/identifiers/key_id.rs | 8 ++++---- crates/ruma-common/src/identifiers/room_id.rs | 2 +- .../src/identifiers/room_or_room_alias_id.rs | 16 ++++++++-------- .../src/identifiers/transaction_id.rs | 2 +- crates/ruma-common/src/identifiers/user_id.rs | 4 ++-- crates/ruma-macros/src/identifiers.rs | 18 +++++++++--------- 10 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/ruma-common/src/identifiers/client_secret.rs b/crates/ruma-common/src/identifiers/client_secret.rs index e7c7204d..7b68bd1c 100644 --- a/crates/ruma-common/src/identifiers/client_secret.rs +++ b/crates/ruma-common/src/identifiers/client_secret.rs @@ -23,7 +23,7 @@ impl ClientSecret { #[cfg(feature = "rand")] pub fn new() -> Box { 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()) } } diff --git a/crates/ruma-common/src/identifiers/device_id.rs b/crates/ruma-common/src/identifiers/device_id.rs index 2b3bf29d..b792de5e 100644 --- a/crates/ruma-common/src/identifiers/device_id.rs +++ b/crates/ruma-common/src/identifiers/device_id.rs @@ -35,7 +35,7 @@ impl DeviceId { /// Generates a random `DeviceId`, suitable for assignment to a new device. #[cfg(feature = "rand")] pub fn new() -> Box { - Self::from_owned(generate_localpart(8)) + Self::from_box(generate_localpart(8)) } } @@ -63,7 +63,7 @@ mod tests { #[test] fn create_device_id_from_box() { let box_str: Box = "ijklmnop".into(); - let device_id: Box = DeviceId::from_owned(box_str); + let device_id: Box = DeviceId::from_box(box_str); assert_eq!(device_id.as_str(), "ijklmnop"); } } diff --git a/crates/ruma-common/src/identifiers/device_key_id.rs b/crates/ruma-common/src/identifiers/device_key_id.rs index 7acdfb2a..d13a9ca5 100644 --- a/crates/ruma-common/src/identifiers/device_key_id.rs +++ b/crates/ruma-common/src/identifiers/device_key_id.rs @@ -21,7 +21,7 @@ impl DeviceKeyId { res.push(':'); res.push_str(device_id); - Self::from_owned(res.into()) + Self::from_box(res.into()) } /// Returns key algorithm of the device key ID. diff --git a/crates/ruma-common/src/identifiers/event_id.rs b/crates/ruma-common/src/identifiers/event_id.rs index b876ae79..69698ae4 100644 --- a/crates/ruma-common/src/identifiers/event_id.rs +++ b/crates/ruma-common/src/identifiers/event_id.rs @@ -49,7 +49,7 @@ impl EventId { /// 1 and 2. #[cfg(feature = "rand")] pub fn new(server_name: &ServerName) -> Box { - 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. diff --git a/crates/ruma-common/src/identifiers/key_id.rs b/crates/ruma-common/src/identifiers/key_id.rs index 2407dc2e..6e43a89e 100644 --- a/crates/ruma-common/src/identifiers/key_id.rs +++ b/crates/ruma-common/src/identifiers/key_id.rs @@ -30,7 +30,7 @@ impl KeyId { res.push(':'); res.push_str(key_name); - Self::from_owned(res.into()) + Self::from_box(res.into()) } /// Returns key algorithm of the key ID. @@ -63,7 +63,7 @@ impl KeyId { unsafe { std::mem::transmute(s) } } - fn from_owned(s: Box) -> Box { + fn from_box(s: Box) -> Box { unsafe { Box::from_raw(Box::into_raw(s) as _) } } @@ -95,7 +95,7 @@ impl ToOwned for KeyId { type Owned = Box>; 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 + Into>, { 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 { diff --git a/crates/ruma-common/src/identifiers/room_id.rs b/crates/ruma-common/src/identifiers/room_id.rs index 24aae9c7..5cb638fa 100644 --- a/crates/ruma-common/src/identifiers/room_id.rs +++ b/crates/ruma-common/src/identifiers/room_id.rs @@ -28,7 +28,7 @@ impl RoomId { /// Fails if the given homeserver cannot be parsed as a valid host. #[cfg(feature = "rand")] pub fn new(server_name: &ServerName) -> Box { - 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. diff --git a/crates/ruma-common/src/identifiers/room_or_room_alias_id.rs b/crates/ruma-common/src/identifiers/room_or_room_alias_id.rs index 955f4096..ddcf2f8a 100644 --- a/crates/ruma-common/src/identifiers/room_or_room_alias_id.rs +++ b/crates/ruma-common/src/identifiers/room_or_room_alias_id.rs @@ -58,8 +58,8 @@ impl RoomOrAliasId { let boxed_str = self.into_owned(); match variant { - Variant::RoomId => either::Either::Left(RoomId::from_owned(boxed_str)), - Variant::RoomAliasId => either::Either::Right(RoomAliasId::from_owned(boxed_str)), + Variant::RoomId => either::Either::Left(RoomId::from_box(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> for Box { fn from(room_id: Box) -> Self { - RoomOrAliasId::from_owned(room_id.into_owned()) + RoomOrAliasId::from_box(room_id.into_owned()) } } impl From> for Box { fn from(room_alias_id: Box) -> Self { - RoomOrAliasId::from_owned(room_alias_id.into_owned()) + RoomOrAliasId::from_box(room_alias_id.into_owned()) } } @@ -133,8 +133,8 @@ impl TryFrom> for Box { fn try_from(id: Box) -> Result, Box> { match id.variant() { - Variant::RoomId => Ok(RoomId::from_owned(id.into_owned())), - Variant::RoomAliasId => Err(RoomAliasId::from_owned(id.into_owned())), + Variant::RoomId => Ok(RoomId::from_box(id.into_owned())), + Variant::RoomAliasId => Err(RoomAliasId::from_box(id.into_owned())), } } } @@ -144,8 +144,8 @@ impl TryFrom> for Box { fn try_from(id: Box) -> Result, Box> { match id.variant() { - Variant::RoomAliasId => Ok(RoomAliasId::from_owned(id.into_owned())), - Variant::RoomId => Err(RoomId::from_owned(id.into_owned())), + Variant::RoomAliasId => Ok(RoomAliasId::from_box(id.into_owned())), + Variant::RoomId => Err(RoomId::from_box(id.into_owned())), } } } diff --git a/crates/ruma-common/src/identifiers/transaction_id.rs b/crates/ruma-common/src/identifiers/transaction_id.rs index e3c89694..763f3e20 100644 --- a/crates/ruma-common/src/identifiers/transaction_id.rs +++ b/crates/ruma-common/src/identifiers/transaction_id.rs @@ -20,6 +20,6 @@ impl TransactionId { #[cfg(feature = "rand")] pub fn new() -> Box { 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()) } } diff --git a/crates/ruma-common/src/identifiers/user_id.rs b/crates/ruma-common/src/identifiers/user_id.rs index e677d216..8cc82fea 100644 --- a/crates/ruma-common/src/identifiers/user_id.rs +++ b/crates/ruma-common/src/identifiers/user_id.rs @@ -26,7 +26,7 @@ impl UserId { /// 12 random ASCII characters. #[cfg(feature = "rand")] pub fn new(server_name: &ServerName) -> Box { - Self::from_owned( + Self::from_box( format!("@{}:{}", super::generate_localpart(12).to_lowercase(), server_name).into(), ) } @@ -48,7 +48,7 @@ impl UserId { Self::parse(id) } else { 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())) } } diff --git a/crates/ruma-macros/src/identifiers.rs b/crates/ruma-macros/src/identifiers.rs index 6d0570ae..fff5c41e 100644 --- a/crates/ruma-macros/src/identifiers.rs +++ b/crates/ruma-macros/src/identifiers.rs @@ -60,7 +60,7 @@ pub fn expand_id_zst(input: ItemStruct) -> syn::Result { unsafe { std::mem::transmute(s) } } - pub(super) fn from_owned(s: Box) -> Box { + pub(super) fn from_box(s: Box) -> Box { unsafe { Box::from_raw(Box::into_raw(s) as _) } } @@ -97,7 +97,7 @@ pub fn expand_id_zst(input: ItemStruct) -> syn::Result { type Owned = Box<#id>; 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 { impl From<&#id> for Box<#id> { 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 + Into>, ) -> Result, crate::IdParseError> { #validate(s.as_ref())?; - Ok(#id::from_owned(s.into())) + Ok(#id::from_box(s.into())) } #[doc = #parse_rc_docs] @@ -396,19 +396,19 @@ fn expand_unchecked_impls(id: &Ident, owned: &Ident) -> TokenStream { impl From<&str> for Box<#id> { fn from(s: &str) -> Self { - #id::from_owned(s.into()) + #id::from_box(s.into()) } } impl From> for Box<#id> { fn from(s: Box) -> Self { - #id::from_owned(s) + #id::from_box(s) } } impl From for Box<#id> { 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 D: serde::Deserializer<'de>, { - Box::::deserialize(deserializer).map(#id::from_owned) + Box::::deserialize(deserializer).map(#id::from_box) } } @@ -433,7 +433,7 @@ fn expand_unchecked_impls(id: &Ident, owned: &Ident) -> TokenStream { D: serde::Deserializer<'de>, { // FIXME: Deserialize inner, convert that - Box::::deserialize(deserializer).map(#id::from_owned).map(Into::into) + Box::::deserialize(deserializer).map(#id::from_box).map(Into::into) } } }