From c2ea1493cb8a177e9d0fdaeba3b5584a34e902c3 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 20 Jul 2020 16:33:29 +0200 Subject: [PATCH] identifiers: Use `.as_ref()` less --- ruma-identifiers/src/device_key_id.rs | 5 ++--- ruma-identifiers/src/event_id.rs | 5 ++--- ruma-identifiers/src/server_key_id.rs | 5 ++--- ruma-identifiers/src/user_id.rs | 9 +++++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ruma-identifiers/src/device_key_id.rs b/ruma-identifiers/src/device_key_id.rs index 120fbace..2584b3ae 100644 --- a/ruma-identifiers/src/device_key_id.rs +++ b/ruma-identifiers/src/device_key_id.rs @@ -13,13 +13,12 @@ pub struct DeviceKeyId { impl DeviceKeyId { /// Returns key algorithm of the device key ID. pub fn algorithm(&self) -> DeviceKeyAlgorithm { - DeviceKeyAlgorithm::from_str(&self.full_id.as_ref()[..self.colon_idx.get() as usize]) - .unwrap() + DeviceKeyAlgorithm::from_str(&self.full_id[..self.colon_idx.get() as usize]).unwrap() } /// Returns device ID of the device key ID. pub fn device_id(&self) -> &DeviceId { - &self.full_id.as_ref()[self.colon_idx.get() as usize + 1..] + &self.full_id[self.colon_idx.get() as usize + 1..] } } diff --git a/ruma-identifiers/src/event_id.rs b/ruma-identifiers/src/event_id.rs index ca922b18..c030f6ae 100644 --- a/ruma-identifiers/src/event_id.rs +++ b/ruma-identifiers/src/event_id.rs @@ -78,9 +78,8 @@ impl EventId { /// /// Only applicable to events in the original format as used by Matrix room versions 1 and 2. pub fn server_name(&self) -> Option<&ServerName> { - self.colon_idx.map(|idx| { - <&ServerName>::try_from(&self.full_id.as_ref()[idx.get() as usize + 1..]).unwrap() - }) + self.colon_idx + .map(|idx| <&ServerName>::try_from(&self.full_id[idx.get() as usize + 1..]).unwrap()) } } diff --git a/ruma-identifiers/src/server_key_id.rs b/ruma-identifiers/src/server_key_id.rs index 50669ce7..f77fb723 100644 --- a/ruma-identifiers/src/server_key_id.rs +++ b/ruma-identifiers/src/server_key_id.rs @@ -14,13 +14,12 @@ pub struct ServerKeyId { impl ServerKeyId { /// Returns key algorithm of the server key ID. pub fn algorithm(&self) -> ServerKeyAlgorithm { - ServerKeyAlgorithm::from_str(&self.full_id.as_ref()[..self.colon_idx.get() as usize]) - .unwrap() + ServerKeyAlgorithm::from_str(&self.full_id[..self.colon_idx.get() as usize]).unwrap() } /// Returns the version of the server key ID. pub fn version(&self) -> &str { - &self.full_id.as_ref()[self.colon_idx.get() as usize + 1..] + &self.full_id[self.colon_idx.get() as usize + 1..] } } diff --git a/ruma-identifiers/src/user_id.rs b/ruma-identifiers/src/user_id.rs index e42ff8b5..8d41a349 100644 --- a/ruma-identifiers/src/user_id.rs +++ b/ruma-identifiers/src/user_id.rs @@ -79,8 +79,7 @@ impl UserId { /// Returns the server name of the user ID. pub fn server_name(&self) -> &ServerName { - <&ServerName>::try_from(&self.full_id.as_ref()[self.colon_idx.get() as usize + 1..]) - .unwrap() + <&ServerName>::try_from(&self.full_id[self.colon_idx.get() as usize + 1..]).unwrap() } /// Whether this user ID is a historical one, i.e. one that doesn't conform to the latest @@ -98,8 +97,10 @@ fn try_from(user_id: S) -> Result where S: AsRef + Into>, { - let colon_idx = parse_id(user_id.as_ref(), &['@'])?; - let localpart = &user_id.as_ref()[1..colon_idx.get() as usize]; + let user_id_str = user_id.as_ref(); + + let colon_idx = parse_id(user_id_str, &['@'])?; + let localpart = &user_id_str[1..colon_idx.get() as usize]; let is_historical = localpart_is_fully_comforming(localpart)?;