From e6595762f60f7832b28251c0e2481a2dcf06af56 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 5 Aug 2023 17:55:40 +0200 Subject: [PATCH] Use the parts/str split in FullJid and BareJid too Since 199b3ae7ae12f909b18fca188a121068b340f718 we allow typed parts to be reused without stringprep being reapplied. This extends it from just Jid to FullJid and BareJid too. --- jid/src/lib.rs | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index efecccf..2369322 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -435,18 +435,34 @@ impl FullJid { FullJid { inner } } - /// The optional node part of the JID. - pub fn node(&self) -> Option<&str> { + /// The optional node part of the JID, as a [`NodePart`] + pub fn node(&self) -> Option { + self.node_str().map(|s| NodePart::new_unchecked(s)) + } + + /// The optional node part of the JID, as a stringy reference + pub fn node_str(&self) -> Option<&str> { self.inner.node() } - /// The domain part of the JID. - pub fn domain(&self) -> &str { + /// The domain part of the JID, as a [`DomainPart`] + pub fn domain(&self) -> DomainPart { + DomainPart::new_unchecked(self.domain_str()) + } + + /// The domain part of the JID, as a stringy reference + pub fn domain_str(&self) -> &str { self.inner.domain() } + /// The optional resource part of the JID, as a [`ResourcePart`]. Since this is a full JID it + /// is always present. + pub fn resource(&self) -> ResourcePart { + ResourcePart::new_unchecked(self.resource_str()) + } + /// The optional resource of the Jabber ID. Since this is a full JID it is always present. - pub fn resource(&self) -> &str { + pub fn resource_str(&self) -> &str { self.inner.resource().unwrap() } @@ -536,13 +552,23 @@ impl BareJid { BareJid { inner } } - /// The optional node part of the JID. - pub fn node(&self) -> Option<&str> { + /// The optional node part of the JID, as a [`NodePart`] + pub fn node(&self) -> Option { + self.node_str().map(|s| NodePart::new_unchecked(s)) + } + + /// The optional node part of the JID, as a stringy reference + pub fn node_str(&self) -> Option<&str> { self.inner.node() } - /// The domain part of the JID. - pub fn domain(&self) -> &str { + /// The domain part of the JID, as a [`DomainPart`] + pub fn domain(&self) -> DomainPart { + DomainPart::new_unchecked(self.domain_str()) + } + + /// The domain part of the JID, as a stringy reference + pub fn domain_str(&self) -> &str { self.inner.domain() }