From 0661078c17b107f47581334eb3df457e90187297 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 12 May 2022 11:20:22 +0200 Subject: [PATCH] client-api: Add From impls for UserIdentifier --- crates/ruma-client-api/CHANGELOG.md | 4 ++++ crates/ruma-client-api/src/uiaa.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index 237d208a..a0d6d49d 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Improvements: + +* Add `From<&UserId>` and `From<&OwnedUserId>` implementations for `UserIdentifier` + # 0.14.0 Bug fixes: diff --git a/crates/ruma-client-api/src/uiaa.rs b/crates/ruma-client-api/src/uiaa.rs index 26f31e7a..4b15157c 100644 --- a/crates/ruma-client-api/src/uiaa.rs +++ b/crates/ruma-client-api/src/uiaa.rs @@ -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 {