identifiers: Use .as_ref()
less
This commit is contained in:
parent
ade43c8516
commit
c2ea1493cb
@ -13,13 +13,12 @@ pub struct DeviceKeyId {
|
|||||||
impl DeviceKeyId {
|
impl DeviceKeyId {
|
||||||
/// Returns key algorithm of the device key ID.
|
/// Returns key algorithm of the device key ID.
|
||||||
pub fn algorithm(&self) -> DeviceKeyAlgorithm {
|
pub fn algorithm(&self) -> DeviceKeyAlgorithm {
|
||||||
DeviceKeyAlgorithm::from_str(&self.full_id.as_ref()[..self.colon_idx.get() as usize])
|
DeviceKeyAlgorithm::from_str(&self.full_id[..self.colon_idx.get() as usize]).unwrap()
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns device ID of the device key ID.
|
/// Returns device ID of the device key ID.
|
||||||
pub fn device_id(&self) -> &DeviceId {
|
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.
|
/// Only applicable to events in the original format as used by Matrix room versions 1 and 2.
|
||||||
pub fn server_name(&self) -> Option<&ServerName> {
|
pub fn server_name(&self) -> Option<&ServerName> {
|
||||||
self.colon_idx.map(|idx| {
|
self.colon_idx
|
||||||
<&ServerName>::try_from(&self.full_id.as_ref()[idx.get() as usize + 1..]).unwrap()
|
.map(|idx| <&ServerName>::try_from(&self.full_id[idx.get() as usize + 1..]).unwrap())
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,13 +14,12 @@ pub struct ServerKeyId {
|
|||||||
impl ServerKeyId {
|
impl ServerKeyId {
|
||||||
/// Returns key algorithm of the server key ID.
|
/// Returns key algorithm of the server key ID.
|
||||||
pub fn algorithm(&self) -> ServerKeyAlgorithm {
|
pub fn algorithm(&self) -> ServerKeyAlgorithm {
|
||||||
ServerKeyAlgorithm::from_str(&self.full_id.as_ref()[..self.colon_idx.get() as usize])
|
ServerKeyAlgorithm::from_str(&self.full_id[..self.colon_idx.get() as usize]).unwrap()
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the version of the server key ID.
|
/// Returns the version of the server key ID.
|
||||||
pub fn version(&self) -> &str {
|
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.
|
/// Returns the server name of the user ID.
|
||||||
pub fn server_name(&self) -> &ServerName {
|
pub fn server_name(&self) -> &ServerName {
|
||||||
<&ServerName>::try_from(&self.full_id.as_ref()[self.colon_idx.get() as usize + 1..])
|
<&ServerName>::try_from(&self.full_id[self.colon_idx.get() as usize + 1..]).unwrap()
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether this user ID is a historical one, i.e. one that doesn't conform to the latest
|
/// 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
|
where
|
||||||
S: AsRef<str> + Into<Box<str>>,
|
S: AsRef<str> + Into<Box<str>>,
|
||||||
{
|
{
|
||||||
let colon_idx = parse_id(user_id.as_ref(), &['@'])?;
|
let user_id_str = user_id.as_ref();
|
||||||
let localpart = &user_id.as_ref()[1..colon_idx.get() as usize];
|
|
||||||
|
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)?;
|
let is_historical = localpart_is_fully_comforming(localpart)?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user