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>) -> Result<OwnedUserId, Error>
 Available on crate feature events only.
pub fn parse(s: impl AsRef<str>) -> Result<OwnedUserId, Error>
events only.Try parsing a &str into an OwnedUserId.
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<UserId>, Error>
 Available on crate feature events only.
pub fn parse_box( s: impl AsRef<str> + Into<Box<str>>, ) -> Result<Box<UserId>, Error>
events only.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) -> OwnedUserId
 Available on crate feature events only.
pub fn new(server_name: &ServerName) -> OwnedUserId
events only.Attempts to generate a UserId for the given origin server with a localpart consisting of
12 random ASCII characters.
The generated OwnedUserId is guaranteed to pass UserId::validate_strict().
Sourcepub fn parse_with_server_name(
    id: impl AsRef<str> + Into<Box<str>>,
    server_name: &ServerName,
) -> Result<OwnedUserId, Error>
 Available on crate feature events only.
pub fn parse_with_server_name( id: impl AsRef<str> + Into<Box<str>>, server_name: &ServerName, ) -> Result<OwnedUserId, Error>
events only.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<UserId>, Error>
 Available on crate feature events only.
pub fn parse_with_server_name_rc( id: impl AsRef<str> + Into<Rc<str>>, server_name: &ServerName, ) -> Result<Rc<UserId>, Error>
events only.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<UserId>, Error>
 Available on crate feature events only.
pub fn parse_with_server_name_arc( id: impl AsRef<str> + Into<Arc<str>>, server_name: &ServerName, ) -> Result<Arc<UserId>, Error>
events only.Variation of parse_with_server_name that returns Arc<Self>.
Sourcepub fn localpart(&self) -> &str
 Available on crate feature events only.
pub fn localpart(&self) -> &str
events only.Returns the user’s localpart.
Sourcepub fn server_name(&self) -> &ServerName
 Available on crate feature events only.
pub fn server_name(&self) -> &ServerName
events only.Returns the server name of the user ID.
Sourcepub fn validate_strict(&self) -> Result<(), Error>
 Available on crate feature events only.
pub fn validate_strict(&self) -> Result<(), Error>
events only.Validate this user ID against the strict grammar.
This should be used to validate newly created user IDs as historical user IDs are deprecated.
Sourcepub fn validate_historical(&self) -> Result<(), Error>
 Available on crate feature events only.
pub fn validate_historical(&self) -> Result<(), Error>
events only.Validate this user ID against the historical grammar.
According to the spec, servers should check events received over federation that contain user IDs with this method, and those that fail should not be forwarded to their users.
Contrary to UserId::is_historical() this method also includes user IDs that conform to
the latest grammar.
Sourcepub fn is_historical(&self) -> bool
 Available on crate feature events only.
pub fn is_historical(&self) -> bool
events only.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
 Available on crate feature events only.
pub fn matrix_to_uri(&self) -> MatrixToUri
events only.Create a matrix.to URI for this user ID.
§Example
use ruma_common::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
 Available on crate feature events only.
pub fn matrix_uri(&self, chat: bool) -> MatrixUri
events only.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_common::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 AsRef<UserId> for OwnedUserId
 
impl AsRef<UserId> for OwnedUserId
Source§impl Borrow<UserId> for OwnedUserId
 
impl Borrow<UserId> for OwnedUserId
Source§impl<'de> Deserialize<'de> for Box<UserId>
 
impl<'de> Deserialize<'de> for Box<UserId>
Source§fn deserialize<D>(
    deserializer: D,
) -> Result<Box<UserId>, <D as Deserializer<'de>>::Error>where
    D: Deserializer<'de>,
 
fn deserialize<D>(
    deserializer: D,
) -> Result<Box<UserId>, <D as Deserializer<'de>>::Error>where
    D: Deserializer<'de>,
Source§impl<'a> From<&'a UserId> for &'a DirectUserIdentifier
 
impl<'a> From<&'a UserId> for &'a DirectUserIdentifier
Source§fn from(value: &'a UserId) -> &'a DirectUserIdentifier
 
fn from(value: &'a UserId) -> &'a DirectUserIdentifier
Source§impl From<&UserId> for OwnedDirectUserIdentifier
 
impl From<&UserId> for OwnedDirectUserIdentifier
Source§fn from(value: &UserId) -> OwnedDirectUserIdentifier
 
fn from(value: &UserId) -> OwnedDirectUserIdentifier
Source§impl From<&UserId> for OwnedUserId
 
impl From<&UserId> for OwnedUserId
Source§fn from(id: &UserId) -> OwnedUserId
 
fn from(id: &UserId) -> OwnedUserId
Source§impl PartialEq<&DirectUserIdentifier> for &UserId
 
impl PartialEq<&DirectUserIdentifier> for &UserId
Source§impl PartialEq<&UserId> for &DirectUserIdentifier
 
impl PartialEq<&UserId> for &DirectUserIdentifier
Source§impl PartialEq<&UserId> for OwnedDirectUserIdentifier
 
impl PartialEq<&UserId> for OwnedDirectUserIdentifier
Source§impl PartialEq<&UserId> for OwnedUserId
 
impl PartialEq<&UserId> for OwnedUserId
Source§impl PartialEq<OwnedDirectUserIdentifier> for &UserId
 
impl PartialEq<OwnedDirectUserIdentifier> for &UserId
Source§impl PartialEq<OwnedUserId> for &UserId
 
impl PartialEq<OwnedUserId> for &UserId
Source§impl PartialEq<OwnedUserId> for UserId
 
impl PartialEq<OwnedUserId> for UserId
Source§impl PartialEq<UserId> for OwnedUserId
 
impl PartialEq<UserId> for OwnedUserId
Source§impl PartialOrd for UserId
 
impl PartialOrd for UserId
Source§impl Serialize for UserId
 
impl Serialize for UserId
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 UserId
 
impl ToOwned for UserId
Source§type Owned = OwnedUserId
 
type Owned = OwnedUserId
Source§fn to_owned(&self) -> <UserId as ToOwned>::Owned
 
fn to_owned(&self) -> <UserId 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 DirectUserIdentifier> for &'a UserId
 
impl<'a> TryFrom<&'a DirectUserIdentifier> for &'a UserId
impl Eq for UserId
impl StructuralPartialEq for UserId
Auto Trait Implementations§
impl Freeze for UserId
impl RefUnwindSafe for UserId
impl Send for UserId
impl !Sized for UserId
impl Sync for UserId
impl Unpin for UserId
impl UnwindSafe for UserId
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.