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>) -> Result<OwnedRoomId, Error>
pub fn parse(s: impl AsRef<str>) -> Result<OwnedRoomId, Error>
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<RoomId>, Error>
pub fn parse_box( s: impl AsRef<str> + Into<Box<str>>, ) -> Result<Box<RoomId>, 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) -> 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) -> Option<&ServerName>
pub fn server_name(&self) -> Option<&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) -> MatrixToUri
pub fn matrix_to_uri_via<T>(&self, via: T) -> MatrixToUri
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,
) -> MatrixToUri
pub fn matrix_to_event_uri_via<T>( &self, ev_id: impl Into<OwnedEventId>, via: T, ) -> MatrixToUri
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) -> MatrixUri
pub fn matrix_uri_via<T>(&self, via: T, join: bool) -> MatrixUri
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,
) -> MatrixUri
pub fn matrix_event_uri_via<T>( &self, ev_id: impl Into<OwnedEventId>, via: T, ) -> MatrixUri
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<Box<RoomId>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Box<RoomId>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<'a> From<&'a RoomId> for &'a RoomOrAliasId
impl<'a> From<&'a RoomId> for &'a RoomOrAliasId
Source§fn from(room_id: &'a RoomId) -> &'a RoomOrAliasId
fn from(room_id: &'a RoomId) -> &'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 OwnedRoomId
impl PartialEq<&RoomId> for OwnedRoomId
Source§impl PartialEq<OwnedRoomId> for &RoomId
impl PartialEq<OwnedRoomId> for &RoomId
Source§impl PartialEq<OwnedRoomId> for RoomId
impl PartialEq<OwnedRoomId> for RoomId
Source§impl PartialEq<RoomId> for OwnedRoomId
impl PartialEq<RoomId> for OwnedRoomId
Source§impl PartialOrd for RoomId
impl PartialOrd for RoomId
Source§impl Serialize for RoomId
impl Serialize for RoomId
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl ToOwned for RoomId
impl ToOwned for RoomId
Source§type Owned = OwnedRoomId
type Owned = OwnedRoomId
Source§fn to_owned(&self) -> <RoomId as ToOwned>::Owned
fn to_owned(&self) -> <RoomId as ToOwned>::Owned
1.63.0 · Source§fn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
Source§impl<'a> TryFrom<&'a RoomOrAliasId> for &'a RoomId
impl<'a> TryFrom<&'a RoomOrAliasId> for &'a RoomId
Source§type Error = &'a RoomAliasId
type Error = &'a RoomAliasId
Source§fn try_from(id: &'a RoomOrAliasId) -> Result<&'a RoomId, &'a RoomAliasId>
fn try_from(id: &'a RoomOrAliasId) -> Result<&'a RoomId, &'a RoomAliasId>
impl Eq for RoomId
impl StructuralPartialEq for RoomId
Auto Trait Implementations§
impl Freeze for RoomId
impl RefUnwindSafe for RoomId
impl Send for RoomId
impl !Sized for RoomId
impl Sync for RoomId
impl Unpin for RoomId
impl UnwindSafe for RoomId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.