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).
This commit is contained in:
Jonas Schäfer 2024-05-14 17:53:53 +02:00
parent 002c2803d4
commit 9b2663a28b

View file

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