RoomId

Struct RoomId 

Source
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

Source

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

pub fn parse_rc(s: impl AsRef<str> + Into<Rc<str>>) -> Result<Rc<Self>, Error>

Try parsing a &str into an Rc<RoomId>.

Source

pub fn parse_arc( s: impl AsRef<str> + Into<Arc<str>>, ) -> Result<Arc<Self>, Error>

Try parsing a &str into an Arc<RoomId>.

Source§

impl RoomId

Source

pub fn as_str(&self) -> &str

Creates a string slice from this RoomId.

Source

pub fn as_bytes(&self) -> &[u8]

Creates a byte slice from this RoomId.

Source§

impl RoomId

Source

pub fn new(server_name: &ServerName) -> Box<Self>

Available on crate feature 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.

Source

pub fn localpart(&self) -> &str

Returns the rooms’s unique ID.

Source

pub fn server_name(&self) -> &ServerName

Returns the server name of the room ID.

Source

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"
);
Source

pub fn matrix_to_event_uri(&self, ev_id: &EventId) -> MatrixToUri

Create a matrix.to URI for an event scoped under this room ID.

Source

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"
);
Source

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 AsRef<str> for Box<RoomId>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<str> for RoomId

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Box<RoomId>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoomId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Box<RoomId>

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for RoomId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a RoomId> for &'a RoomOrAliasId

Source§

fn from(room_id: &'a RoomId) -> Self

Converts to this type from the input type.
Source§

impl From<&RoomId> for Arc<RoomId>

Source§

fn from(s: &RoomId) -> Arc<RoomId>

Converts to this type from the input type.
Source§

impl From<&RoomId> for Box<RoomId>

Source§

fn from(id: &RoomId) -> Self

Converts to this type from the input type.
Source§

impl From<&RoomId> for MatrixId

Source§

fn from(room_id: &RoomId) -> Self

Converts to this type from the input type.
Source§

impl From<&RoomId> for Rc<RoomId>

Source§

fn from(s: &RoomId) -> Rc<RoomId>

Converts to this type from the input type.
Source§

impl FromStr for Box<RoomId>

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for RoomId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
Source§

impl Ord for RoomId

Source§

fn cmp(&self, other: &RoomId) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq<&RoomId> for Box<RoomId>

Source§

fn eq(&self, other: &&RoomId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for Box<RoomId>

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for RoomId

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Box<RoomId>> for &RoomId

Source§

fn eq(&self, other: &Box<RoomId>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Box<RoomId>> for RoomId

Source§

fn eq(&self, other: &Box<RoomId>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RoomId> for &str

Source§

fn eq(&self, other: &RoomId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RoomId> for Box<RoomId>

Source§

fn eq(&self, other: &RoomId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RoomId> for String

Source§

fn eq(&self, other: &RoomId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<RoomId> for str

Source§

fn eq(&self, other: &RoomId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for Box<RoomId>

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for RoomId

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Box<RoomId>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for RoomId

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for RoomId

Source§

fn eq(&self, other: &RoomId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for RoomId

Source§

fn partial_cmp(&self, other: &RoomId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for RoomId

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToOwned for RoomId

Source§

type Owned = Box<RoomId>

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · Source§

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<'a> TryFrom<&'a RoomOrAliasId> for &'a RoomId

Source§

type Error = &'a RoomAliasId

The type returned in the event of a conversion error.
Source§

fn try_from(id: &'a RoomOrAliasId) -> Result<&'a RoomId, &'a RoomAliasId>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a str> for &'a RoomId

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Box<RoomId>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Box<RoomOrAliasId>> for Box<RoomId>

Source§

type Error = Box<RoomAliasId>

The type returned in the event of a conversion error.
Source§

fn try_from(id: Box<RoomOrAliasId>) -> Result<Box<RoomId>, Box<RoomAliasId>>

Performs the conversion.
Source§

impl TryFrom<String> for Box<RoomId>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(s: String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for RoomId

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more