Add more specific `into_*` conversion functions to specific JID subtypes

Jonas Schäfer created

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).

Change summary

jid/src/lib.rs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

Detailed changes

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")]