diff --git a/crates/ruma-identifiers/src/macros.rs b/crates/ruma-identifiers/src/macros.rs index 4d15af51..a2503234 100644 --- a/crates/ruma-identifiers/src/macros.rs +++ b/crates/ruma-identifiers/src/macros.rs @@ -35,7 +35,7 @@ macro_rules! opaque_identifier_common_impls { unsafe { Box::from_raw(Box::into_raw(s) as _) } } - fn into_owned(self: Box) -> Box { + pub(super) fn into_owned(self: Box) -> Box { unsafe { Box::from_raw(Box::into_raw(self) as _) } } diff --git a/crates/ruma-identifiers/src/room_or_room_alias_id.rs b/crates/ruma-identifiers/src/room_or_room_alias_id.rs index 5e977c78..d9f1d026 100644 --- a/crates/ruma-identifiers/src/room_or_room_alias_id.rs +++ b/crates/ruma-identifiers/src/room_or_room_alias_id.rs @@ -1,9 +1,6 @@ //! Matrix identifiers for places where a room ID or room alias ID are used interchangeably. -use std::{ - convert::{TryFrom, TryInto}, - hint::unreachable_unchecked, -}; +use std::{convert::TryFrom, hint::unreachable_unchecked}; use crate::{server_name::ServerName, RoomAliasId, RoomId}; @@ -89,13 +86,13 @@ enum Variant { impl From> for Box { fn from(room_id: Box) -> Self { - Self::try_from(room_id.as_str()).unwrap() + RoomOrAliasId::from_owned(room_id.into_owned()) } } impl From> for Box { fn from(room_alias_id: Box) -> Self { - Self::try_from(room_alias_id.as_str()).unwrap() + RoomOrAliasId::from_owned(room_alias_id.into_owned()) } } @@ -104,8 +101,8 @@ impl TryFrom> for Box { fn try_from(id: Box) -> Result, Box> { match id.variant() { - Variant::RoomId => Ok(id.as_str().try_into().unwrap()), - Variant::RoomAliasId => Err(id.as_str().try_into().unwrap()), + Variant::RoomId => Ok(RoomId::from_owned(id.into_owned())), + Variant::RoomAliasId => Err(RoomAliasId::from_owned(id.into_owned())), } } } @@ -115,8 +112,8 @@ impl TryFrom> for Box { fn try_from(id: Box) -> Result, Box> { match id.variant() { - Variant::RoomAliasId => Ok(id.as_str().try_into().unwrap()), - Variant::RoomId => Err(id.as_str().try_into().unwrap()), + Variant::RoomAliasId => Ok(RoomAliasId::from_owned(id.into_owned())), + Variant::RoomId => Err(RoomId::from_owned(id.into_owned())), } } }