From 9b2663a28bde5737dcc977928282d41dd9737df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sch=C3=A4fer?= Date: Tue, 14 May 2024 17:53:53 +0200 Subject: [PATCH] Add more specific `into_*` conversion functions to specific JID subtypes This is necessary because `into_inner()` as implemented on Jid consumes the value. That means it cannot be called through Deref (because that only takes a reference). --- jid/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index 18e1133..16078e1 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -720,6 +720,24 @@ impl FullJid { pub fn resource(&self) -> &ResourceRef { self.inner.resource().unwrap() } + + /// Return the inner String of this full JID. + pub fn into_inner(self) -> String { + self.inner.into_inner() + } + + /// Transforms this full JID into a [`BareJid`], throwing away the + /// resource. + /// + /// ``` + /// # use jid::{BareJid, FullJid}; + /// let jid: FullJid = "foo@bar/baz".parse().unwrap(); + /// let bare = jid.into_bare(); + /// assert_eq!(bare.to_string(), "foo@bar"); + /// ``` + pub fn into_bare(self) -> BareJid { + self.inner.into_bare() + } } impl FromStr for BareJid { @@ -826,6 +844,11 @@ impl BareJid { let resource = ResourcePart::new(resource)?; Ok(self.with_resource(&resource)) } + + /// Return the inner String of this bare JID. + pub fn into_inner(self) -> String { + self.inner.into_inner() + } } #[cfg(feature = "minidom")]