Struct ruma_common::RoomId
source · pub struct RoomId(_);
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>) -> Result<OwnedRoomId, IdParseError>
pub fn parse(s: impl AsRef<str>) -> Result<OwnedRoomId, IdParseError>
Try parsing a &str
into an OwnedRoomId
.
The same can also be done using FromStr
, TryFrom
or TryInto
.
This function is simply more constrained and thus useful in generic contexts.
sourcepub fn parse_box(
s: impl AsRef<str> + Into<Box<str>>
) -> Result<Box<Self>, IdParseError>
pub fn parse_box( s: impl AsRef<str> + Into<Box<str>> ) -> Result<Box<Self>, IdParseError>
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) -> OwnedRoomId
Available on crate feature rand
only.
pub fn new(server_name: &ServerName) -> OwnedRoomId
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(&self) -> MatrixToUri
pub fn matrix_to_uri(&self) -> MatrixToUri
Create a matrix.to
URI for this room ID.
Note that it is recommended to provide servers that should know the room to be able to find
it with its room ID. For that use RoomId::matrix_to_uri_via()
.
Example
use ruma_common::{room_id, server_name};
assert_eq!(
room_id!("!somewhere:example.org").matrix_to_uri().to_string(),
"https://matrix.to/#/!somewhere:example.org"
);
sourcepub fn matrix_to_uri_via<T>(&self, via: T) -> MatrixToUriwhere
T: IntoIterator,
T::Item: Into<OwnedServerName>,
pub fn matrix_to_uri_via<T>(&self, via: T) -> MatrixToUriwhere T: IntoIterator, T::Item: Into<OwnedServerName>,
Create a matrix.to
URI for this room ID with a list of servers that should know it.
To get the list of servers, it is recommended to use the routing algorithm from the spec.
If you don’t have a list of servers, you can use RoomId::matrix_to_uri()
instead.
Example
use ruma_common::{room_id, server_name};
assert_eq!(
room_id!("!somewhere:example.org")
.matrix_to_uri_via([&*server_name!("example.org"), &*server_name!("alt.example.org")])
.to_string(),
"https://matrix.to/#/!somewhere:example.org?via=example.org&via=alt.example.org"
);
sourcepub fn matrix_to_event_uri(&self, ev_id: impl Into<OwnedEventId>) -> MatrixToUri
pub fn matrix_to_event_uri(&self, ev_id: impl Into<OwnedEventId>) -> MatrixToUri
Create a matrix.to
URI for an event scoped under this room ID.
Note that it is recommended to provide servers that should know the room to be able to find
it with its room ID. For that use RoomId::matrix_to_event_uri_via()
.
sourcepub fn matrix_to_event_uri_via<T>(
&self,
ev_id: impl Into<OwnedEventId>,
via: T
) -> MatrixToUriwhere
T: IntoIterator,
T::Item: Into<OwnedServerName>,
pub fn matrix_to_event_uri_via<T>( &self, ev_id: impl Into<OwnedEventId>, via: T ) -> MatrixToUriwhere T: IntoIterator, T::Item: Into<OwnedServerName>,
Create a matrix.to
URI for an event scoped under this room ID with a list of servers that
should know it.
To get the list of servers, it is recommended to use the routing algorithm from the spec.
If you don’t have a list of servers, you can use RoomId::matrix_to_event_uri()
instead.
sourcepub fn matrix_uri(&self, join: bool) -> MatrixUri
pub fn matrix_uri(&self, join: bool) -> MatrixUri
Create a matrix:
URI for this room ID.
If join
is true
, a click on the URI should join the room.
Note that it is recommended to provide servers that should know the room to be able to find
it with its room ID. For that use RoomId::matrix_uri_via()
.
Example
use ruma_common::{room_id, server_name};
assert_eq!(
room_id!("!somewhere:example.org").matrix_uri(false).to_string(),
"matrix:roomid/somewhere:example.org"
);
sourcepub fn matrix_uri_via<T>(&self, via: T, join: bool) -> MatrixUriwhere
T: IntoIterator,
T::Item: Into<OwnedServerName>,
pub fn matrix_uri_via<T>(&self, via: T, join: bool) -> MatrixUriwhere T: IntoIterator, T::Item: Into<OwnedServerName>,
Create a matrix:
URI for this room ID with a list of servers that should know it.
To get the list of servers, it is recommended to use the routing algorithm from the spec.
If you don’t have a list of servers, you can use RoomId::matrix_uri()
instead.
If join
is true
, a click on the URI should join the room.
Example
use ruma_common::{room_id, server_name};
assert_eq!(
room_id!("!somewhere:example.org")
.matrix_uri_via(
[&*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(&self, ev_id: impl Into<OwnedEventId>) -> MatrixUri
pub fn matrix_event_uri(&self, ev_id: impl Into<OwnedEventId>) -> MatrixUri
Create a matrix:
URI for an event scoped under this room ID.
Note that it is recommended to provide servers that should know the room to be able to find
it with its room ID. For that use RoomId::matrix_event_uri_via()
.
sourcepub fn matrix_event_uri_via<T>(
&self,
ev_id: impl Into<OwnedEventId>,
via: T
) -> MatrixUriwhere
T: IntoIterator,
T::Item: Into<OwnedServerName>,
pub fn matrix_event_uri_via<T>( &self, ev_id: impl Into<OwnedEventId>, via: T ) -> MatrixUriwhere T: IntoIterator, T::Item: Into<OwnedServerName>,
Create a matrix:
URI for an event scoped under this room ID with a list of servers that
should know it.
To get the list of servers, it is recommended to use the routing algorithm from the spec.
If you don’t have a list of servers, you can use RoomId::matrix_event_uri()
instead.
Trait Implementations§
source§impl AsRef<RoomId> for OwnedRoomId
impl AsRef<RoomId> for OwnedRoomId
source§impl Borrow<RoomId> for OwnedRoomId
impl Borrow<RoomId> for OwnedRoomId
source§impl<'de> Deserialize<'de> for Box<RoomId>
impl<'de> Deserialize<'de> for Box<RoomId>
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl<'a> From<&'a RoomId> for &'a RoomOrAliasId
impl<'a> From<&'a RoomId> for &'a RoomOrAliasId
source§impl From<&RoomId> for OwnedRoomId
impl From<&RoomId> for OwnedRoomId
source§fn from(id: &RoomId) -> OwnedRoomId
fn from(id: &RoomId) -> OwnedRoomId
source§impl PartialEq<&RoomId> for Box<RoomId>
impl PartialEq<&RoomId> for Box<RoomId>
source§impl PartialEq<&RoomId> for OwnedRoomId
impl PartialEq<&RoomId> for OwnedRoomId
source§impl PartialEq<&str> for Box<RoomId>
impl PartialEq<&str> for Box<RoomId>
source§impl PartialEq<&str> for RoomId
impl PartialEq<&str> for RoomId
source§impl PartialEq<Box<RoomId, Global>> for &RoomId
impl PartialEq<Box<RoomId, Global>> for &RoomId
source§impl PartialEq<Box<RoomId, Global>> for RoomId
impl PartialEq<Box<RoomId, Global>> for RoomId
source§impl PartialEq<OwnedRoomId> for &RoomId
impl PartialEq<OwnedRoomId> for &RoomId
source§fn eq(&self, other: &OwnedRoomId) -> bool
fn eq(&self, other: &OwnedRoomId) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<OwnedRoomId> for Box<RoomId>
impl PartialEq<OwnedRoomId> for Box<RoomId>
source§fn eq(&self, other: &OwnedRoomId) -> bool
fn eq(&self, other: &OwnedRoomId) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<OwnedRoomId> for RoomId
impl PartialEq<OwnedRoomId> for RoomId
source§fn eq(&self, other: &OwnedRoomId) -> bool
fn eq(&self, other: &OwnedRoomId) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<RoomId> for &str
impl PartialEq<RoomId> for &str
source§impl PartialEq<RoomId> for Box<RoomId>
impl PartialEq<RoomId> for Box<RoomId>
source§impl PartialEq<RoomId> for OwnedRoomId
impl PartialEq<RoomId> for OwnedRoomId
source§impl PartialEq<RoomId> for RoomId
impl PartialEq<RoomId> for RoomId
source§impl PartialEq<RoomId> for String
impl PartialEq<RoomId> for String
source§impl PartialEq<RoomId> for str
impl PartialEq<RoomId> for str
source§impl PartialEq<String> for Box<RoomId>
impl PartialEq<String> for Box<RoomId>
source§impl PartialEq<String> for RoomId
impl PartialEq<String> for RoomId
source§impl PartialOrd<RoomId> for RoomId
impl PartialOrd<RoomId> for RoomId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more