identifiers: Improve readability of server_name methods
This commit is contained in:
parent
27a2e1f97f
commit
e147308277
@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! [MXC URI]: https://matrix.org/docs/spec/client_server/r0.6.1#mxc-uri
|
//! [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};
|
use ruma_identifiers_validation::{error::MxcUriError, mxc_uri::validate};
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ impl MxcUri {
|
|||||||
pub fn parts(&self) -> Result<(&ServerName, &str)> {
|
pub fn parts(&self) -> Result<(&ServerName, &str)> {
|
||||||
self.extract_slash_idx().map(|idx| {
|
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..],
|
&self.full_uri[idx.get() as usize + 1..],
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix room alias identifiers.
|
//! Matrix room alias identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
use std::{convert::TryInto, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::server_name::ServerName;
|
use crate::server_name::ServerName;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ impl RoomAliasId {
|
|||||||
|
|
||||||
/// Returns the server name of the room alias ID.
|
/// Returns the server name of the room alias ID.
|
||||||
pub fn server_name(&self) -> &ServerName {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix room identifiers.
|
//! Matrix room identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
use std::{convert::TryInto, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::ServerName;
|
use crate::ServerName;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ impl RoomId {
|
|||||||
|
|
||||||
/// Returns the server name of the room ID.
|
/// Returns the server name of the room ID.
|
||||||
pub fn server_name(&self) -> &ServerName {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Matrix user identifiers.
|
//! Matrix user identifiers.
|
||||||
|
|
||||||
use std::{convert::TryFrom, fmt, num::NonZeroU8};
|
use std::{convert::TryInto, fmt, num::NonZeroU8};
|
||||||
|
|
||||||
use crate::ServerName;
|
use crate::ServerName;
|
||||||
|
|
||||||
@ -82,7 +82,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[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.
|
/// Whether this user ID is a historical one.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user