From 8161360852baceebdb660845af314ca57461d714 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 17 May 2022 13:32:59 +0200 Subject: [PATCH] feat(crypto): Add `toString` methods on identifier objects. --- crates/matrix-sdk-crypto/src/js/identifiers.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/matrix-sdk-crypto/src/js/identifiers.rs b/crates/matrix-sdk-crypto/src/js/identifiers.rs index efc782202..7623b54a7 100644 --- a/crates/matrix-sdk-crypto/src/js/identifiers.rs +++ b/crates/matrix-sdk-crypto/src/js/identifiers.rs @@ -40,6 +40,12 @@ impl UserId { pub fn is_historical(&self) -> bool { self.inner.is_historical() } + + /// Return the user ID as a string. + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.inner.as_str().to_owned() + } } /// A Matrix key ID. @@ -59,6 +65,12 @@ impl DeviceId { pub fn new(id: &str) -> DeviceId { Self { inner: id.into() } } + + /// Return the device ID as a string. + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.inner.as_str().to_owned() + } } /// A Matrix [room ID]. @@ -88,6 +100,12 @@ impl RoomId { pub fn server_name(&self) -> ServerName { ServerName { inner: self.inner.server_name().to_owned() } } + + /// Return the device ID as a string. + #[wasm_bindgen(js_name = "toString")] + pub fn to_string(&self) -> String { + self.inner.as_str().to_owned() + } } /// A Matrix-spec compliant [server name].