identifiers: Use .as_ref()
less
This commit is contained in:
parent
ade43c8516
commit
c2ea1493cb
@ -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..]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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..]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)?;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user