Struct ruma_common::UserId
source · [−]#[repr(transparent)]pub struct UserId(_);
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
sourceimpl UserId
impl UserId
sourcepub fn parse(s: impl AsRef<str>) -> Result<OwnedUserId, IdParseError>
pub fn parse(s: impl AsRef<str>) -> Result<OwnedUserId, IdParseError>
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<Self>, IdParseError>
pub fn parse_box(
s: impl AsRef<str> + Into<Box<str>>
) -> Result<Box<Self>, IdParseError>
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.
sourceimpl UserId
impl UserId
sourcepub fn new(server_name: &ServerName) -> OwnedUserId
pub fn new(server_name: &ServerName) -> OwnedUserId
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<OwnedUserId, IdParseError>
pub fn parse_with_server_name(
id: impl AsRef<str> + Into<Box<str>>,
server_name: &ServerName
) -> Result<OwnedUserId, IdParseError>
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>, IdParseError>
pub fn parse_with_server_name_rc(
id: impl AsRef<str> + Into<Rc<str>>,
server_name: &ServerName
) -> Result<Rc<Self>, IdParseError>
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>, IdParseError>
pub fn parse_with_server_name_arc(
id: impl AsRef<str> + Into<Arc<str>>,
server_name: &ServerName
) -> Result<Arc<Self>, IdParseError>
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_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
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_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
sourceimpl AsRef<UserId> for OwnedUserId
impl AsRef<UserId> for OwnedUserId
sourceimpl Borrow<UserId> for OwnedUserId
impl Borrow<UserId> for OwnedUserId
sourceimpl<'de> Deserialize<'de> for Box<UserId>
impl<'de> Deserialize<'de> for Box<UserId>
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<&UserId> for OwnedUserId
impl From<&UserId> for OwnedUserId
sourcefn from(id: &UserId) -> OwnedUserId
fn from(id: &UserId) -> OwnedUserId
Converts to this type from the input type.
sourceimpl Ord for UserId
impl Ord for UserId
sourceimpl PartialEq<&UserId> for OwnedUserId
impl PartialEq<&UserId> for OwnedUserId
sourceimpl PartialEq<OwnedUserId> for UserId
impl PartialEq<OwnedUserId> for UserId
sourceimpl PartialEq<OwnedUserId> for &UserId
impl PartialEq<OwnedUserId> for &UserId
sourceimpl PartialEq<OwnedUserId> for Box<UserId>
impl PartialEq<OwnedUserId> for Box<UserId>
sourceimpl PartialEq<UserId> for OwnedUserId
impl PartialEq<UserId> for OwnedUserId
sourceimpl PartialOrd<UserId> for UserId
impl PartialOrd<UserId> for UserId
sourcefn partial_cmp(&self, other: &UserId) -> Option<Ordering>
fn partial_cmp(&self, other: &UserId) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl ToOwned for UserId
impl ToOwned for UserId
type Owned = OwnedUserId
type Owned = OwnedUserId
The resulting type after obtaining ownership.
sourcefn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · sourcefn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
Uses borrowed data to replace owned data, usually by cloning. Read more
impl Eq for UserId
impl StructuralEq for UserId
impl StructuralPartialEq for UserId
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.