From 0dcbec5fa7760caf6873b8b19c4207788c6e0877 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 5 Apr 2021 21:41:54 +0200 Subject: [PATCH] identifiers: Add more conversion methods and a trait impl --- ruma-identifiers/src/macros.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ruma-identifiers/src/macros.rs b/ruma-identifiers/src/macros.rs index 4cd2c097..3615d0c5 100644 --- a/ruma-identifiers/src/macros.rs +++ b/ruma-identifiers/src/macros.rs @@ -92,11 +92,31 @@ macro_rules! common_impls { self.full_id.as_bytes() } } + + doc_concat! { + #[doc = concat!("Converts this `", stringify!($id), "` into a `String`")] + pub fn into_string(self) -> String { + self.full_id.into() + } + } + + doc_concat! { + #[doc = concat!("Converts this `", stringify!($id), "` into a `Vec`")] + pub fn into_bytes(self) -> Vec { + Box::<[u8]>::from(self.full_id).into() + } + } } impl ::std::convert::From<$id> for ::std::string::String { fn from(id: $id) -> Self { - id.full_id.into() + id.into_string() + } + } + + impl ::std::convert::From<$id> for ::std::vec::Vec { + fn from(id: $id) -> Self { + id.into_bytes() } }