identifiers: Improve readability of server_name methods

This commit is contained in:
Jonas Platte 2021-09-23 18:54:03 +02:00
parent 27a2e1f97f
commit e147308277
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
4 changed files with 8 additions and 8 deletions

View File

@ -2,7 +2,7 @@
//!
//! [MXC URI]: https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri
use std::{convert::TryFrom, fmt, num::NonZeroU8};
use std::{convert::TryInto, fmt, num::NonZeroU8};
use ruma_identifiers_validation::{error::MxcUriError, mxc_uri::validate};
@ -34,7 +34,7 @@ impl MxcUri {
pub fn parts(&self) -> Result<(&ServerName, &str)> {
self.extract_slash_idx().map(|idx| {
(
<&ServerName>::try_from(&self.full_uri[6..idx.get() as usize]).unwrap(),
self.full_uri[6..idx.get() as usize].try_into().unwrap(),
&self.full_uri[idx.get() as usize + 1..],
)
})

View File

@ -1,6 +1,6 @@
//! Matrix room alias identifiers.
use std::{convert::TryFrom, fmt, num::NonZeroU8};
use std::{convert::TryInto, fmt, num::NonZeroU8};
use crate::server_name::ServerName;
@ -37,7 +37,7 @@ impl RoomAliasId {
/// Returns the server name of the room alias ID.
pub fn server_name(&self) -> &ServerName {
<&ServerName>::try_from(&self.full_id[self.colon_idx.get() as usize + 1..]).unwrap()
self.full_id[self.colon_idx.get() as usize + 1..].try_into().unwrap()
}
}

View File

@ -1,6 +1,6 @@
//! Matrix room identifiers.
use std::{convert::TryFrom, fmt, num::NonZeroU8};
use std::{convert::TryInto, fmt, num::NonZeroU8};
use crate::ServerName;
@ -51,7 +51,7 @@ impl RoomId {
/// Returns the server name of the room ID.
pub fn server_name(&self) -> &ServerName {
<&ServerName>::try_from(&self.full_id[self.colon_idx.get() as usize + 1..]).unwrap()
self.full_id[self.colon_idx.get() as usize + 1..].try_into().unwrap()
}
}

View File

@ -1,6 +1,6 @@
//! Matrix user identifiers.
use std::{convert::TryFrom, fmt, num::NonZeroU8};
use std::{convert::TryInto, fmt, num::NonZeroU8};
use crate::ServerName;
@ -82,7 +82,7 @@ impl UserId {
/// Returns the server name of the user ID.
pub fn server_name(&self) -> &ServerName {
<&ServerName>::try_from(&self.full_id[self.colon_idx.get() as usize + 1..]).unwrap()
self.full_id[self.colon_idx.get() as usize + 1..].try_into().unwrap()
}
/// Whether this user ID is a historical one.