pub struct RoomId(/* private fields */);Expand description
A Matrix room ID.
A RoomId is generated randomly or converted from a string slice, and can be converted back
into a string as needed.
assert_eq!(<&RoomId>::try_from("!n8f893n9:example.com").unwrap(), "!n8f893n9:example.com");Implementations§
Source§impl RoomId
impl RoomId
Sourcepub fn parse(s: impl AsRef<str> + Into<Box<str>>) -> Result<Box<Self>, Error>
pub fn parse(s: impl AsRef<str> + Into<Box<str>>) -> Result<Box<Self>, Error>
Try parsing a &str into a Box<RoomId>.
The same can also be done using FromStr, TryFrom or TryInto.
This function is simply more constrained and thus useful in generic contexts.
Source§impl RoomId
impl RoomId
Sourcepub fn new(server_name: &ServerName) -> Box<Self>
Available on crate feature rand only.
pub fn new(server_name: &ServerName) -> Box<Self>
rand only.Attempts to generate a RoomId for the given origin server with a localpart consisting of
18 random ASCII characters.
Fails if the given homeserver cannot be parsed as a valid host.
Sourcepub fn server_name(&self) -> &ServerName
pub fn server_name(&self) -> &ServerName
Returns the server name of the room ID.
Sourcepub fn matrix_to_uri<'a>(
&self,
via: impl IntoIterator<Item = &'a ServerName>,
) -> MatrixToUri
pub fn matrix_to_uri<'a>( &self, via: impl IntoIterator<Item = &'a ServerName>, ) -> MatrixToUri
Create a matrix.to URI for this room ID.
§Example
use ruma_identifiers::{room_id, server_name};
assert_eq!(
room_id!("!somewhere:example.org")
.matrix_to_uri([&*server_name!("example.org"), &*server_name!("alt.example.org")])
.to_string(),
"https://matrix.to/#/%21somewhere%3Aexample.org?via=example.org&via=alt.example.org"
);Sourcepub fn matrix_to_event_uri(&self, ev_id: &EventId) -> MatrixToUri
pub fn matrix_to_event_uri(&self, ev_id: &EventId) -> MatrixToUri
Create a matrix.to URI for an event scoped under this room ID.
Sourcepub fn matrix_uri<'a>(
&self,
via: impl IntoIterator<Item = &'a ServerName>,
join: bool,
) -> MatrixUri
pub fn matrix_uri<'a>( &self, via: impl IntoIterator<Item = &'a ServerName>, join: bool, ) -> MatrixUri
Create a matrix: URI for this room ID.
If join is true, a click on the URI should join the room.
§Example
use ruma_identifiers::{room_id, server_name};
assert_eq!(
room_id!("!somewhere:example.org")
.matrix_uri([&*server_name!("example.org"), &*server_name!("alt.example.org")], true)
.to_string(),
"matrix:roomid/somewhere:example.org?via=example.org&via=alt.example.org&action=join"
);Sourcepub fn matrix_event_uri<'a>(
&self,
ev_id: &EventId,
via: impl IntoIterator<Item = &'a ServerName>,
) -> MatrixUri
pub fn matrix_event_uri<'a>( &self, ev_id: &EventId, via: impl IntoIterator<Item = &'a ServerName>, ) -> MatrixUri
Create a matrix: URI for an event scoped under this room ID.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Box<RoomId>
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Box<RoomId>
serde only.