client-api: Add From impls for UserIdentifier

This commit is contained in:
Jonas Platte 2022-05-12 11:20:22 +02:00 committed by Jonas Platte
parent af07bfb8f4
commit 0661078c17
2 changed files with 17 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# [unreleased]
Improvements:
* Add `From<&UserId>` and `From<&OwnedUserId>` implementations for `UserIdentifier`
# 0.14.0
Bug fixes:

View File

@ -12,7 +12,7 @@ use ruma_common::{
},
serde::{from_raw_json_value, Incoming, JsonObject, StringEnum},
thirdparty::Medium,
ClientSecret, OwnedSessionId,
ClientSecret, OwnedSessionId, OwnedUserId, UserId,
};
use serde::{
de::{self, DeserializeOwned},
@ -590,6 +590,18 @@ pub enum UserIdentifier<'a> {
},
}
impl<'a> From<&'a UserId> for UserIdentifier<'a> {
fn from(id: &'a UserId) -> Self {
Self::UserIdOrLocalpart(id.as_str())
}
}
impl<'a> From<&'a OwnedUserId> for UserIdentifier<'a> {
fn from(id: &'a OwnedUserId) -> Self {
Self::UserIdOrLocalpart(id.as_str())
}
}
impl IncomingUserIdentifier {
pub(crate) fn to_outgoing(&self) -> UserIdentifier<'_> {
match self {