pub struct UserId(/* private fields */);Expand description
A Matrix user ID.
A UserId is generated randomly or converted from a string slice, and can be converted back
into a string as needed.
assert_eq!(<&UserId>::try_from("@carl:example.com").unwrap(), "@carl:example.com");Implementations§
Source§impl UserId
impl UserId
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<UserId>.
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 UserId
impl UserId
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 UserId for the given origin server with a localpart consisting of
12 random ASCII characters.
Sourcepub fn parse_with_server_name(
id: impl AsRef<str> + Into<Box<str>>,
server_name: &ServerName,
) -> Result<Box<Self>, Error>
pub fn parse_with_server_name( id: impl AsRef<str> + Into<Box<str>>, server_name: &ServerName, ) -> Result<Box<Self>, Error>
Attempts to complete a user ID, by adding the colon + server name and @ prefix, if not
present already.
This is a convenience function for the login API, where a user can supply either their full
user ID or just the localpart. It only supports a valid user ID or a valid user ID
localpart, not the localpart plus the @ prefix, or the localpart plus server name without
the @ prefix.
Sourcepub fn parse_with_server_name_rc(
id: impl AsRef<str> + Into<Rc<str>>,
server_name: &ServerName,
) -> Result<Rc<Self>, Error>
pub fn parse_with_server_name_rc( id: impl AsRef<str> + Into<Rc<str>>, server_name: &ServerName, ) -> Result<Rc<Self>, Error>
Variation of parse_with_server_name that returns Rc<Self>.
Sourcepub fn parse_with_server_name_arc(
id: impl AsRef<str> + Into<Arc<str>>,
server_name: &ServerName,
) -> Result<Arc<Self>, Error>
pub fn parse_with_server_name_arc( id: impl AsRef<str> + Into<Arc<str>>, server_name: &ServerName, ) -> Result<Arc<Self>, Error>
Variation of parse_with_server_name that returns Arc<Self>.
Sourcepub fn server_name(&self) -> &ServerName
pub fn server_name(&self) -> &ServerName
Returns the server name of the user ID.
Sourcepub fn is_historical(&self) -> bool
pub fn is_historical(&self) -> bool
Whether this user ID is a historical one.
A historical user ID is one that doesn’t conform to the latest specification of the user ID grammar but is still accepted because it was previously allowed.
Sourcepub fn matrix_to_uri(&self) -> MatrixToUri
pub fn matrix_to_uri(&self) -> MatrixToUri
Create a matrix.to URI for this user ID.
§Example
use ruma_identifiers::user_id;
let message = format!(
r#"Thanks for the update <a href="{link}">{display_name}</a>."#,
link = user_id!("@jplatte:notareal.hs").matrix_to_uri(),
display_name = "jplatte",
);Sourcepub fn matrix_uri(&self, chat: bool) -> MatrixUri
pub fn matrix_uri(&self, chat: bool) -> MatrixUri
Create a matrix: URI for this user ID.
If chat is true, a click on the URI should start a direct message
with the user.
§Example
use ruma_identifiers::user_id;
let message = format!(
r#"Thanks for the update <a href="{link}">{display_name}</a>."#,
link = user_id!("@jplatte:notareal.hs").matrix_uri(false),
display_name = "jplatte",
);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Box<UserId>
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Box<UserId>
serde only.