identifiers: Use .as_ref() less

This commit is contained in:
Jonas Platte 2020-07-20 16:33:29 +02:00
parent ade43c8516
commit c2ea1493cb
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
4 changed files with 11 additions and 13 deletions

View File

@ -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..]
}
}

View File

@ -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())
}
}

View File

@ -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..]
}
}

View File

@ -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<S>(user_id: S) -> Result<UserId, Error>
where
S: AsRef<str> + Into<Box<str>>,
{
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)?;