Use the parts/str split in FullJid and BareJid too

Since 199b3ae7ae we allow typed parts to
be reused without stringprep being reapplied.  This extends it from just
Jid to FullJid and BareJid too.
This commit is contained in:
Emmanuel Gil Peyrot 2023-08-05 17:55:40 +02:00 committed by pep
parent 6ccee76621
commit e6595762f6

View file

@ -435,18 +435,34 @@ impl FullJid {
FullJid { inner } FullJid { inner }
} }
/// The optional node part of the JID. /// The optional node part of the JID, as a [`NodePart`]
pub fn node(&self) -> Option<&str> { pub fn node(&self) -> Option<NodePart> {
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() self.inner.node()
} }
/// The domain part of the JID. /// The domain part of the JID, as a [`DomainPart`]
pub fn domain(&self) -> &str { 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() 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. /// 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() self.inner.resource().unwrap()
} }
@ -536,13 +552,23 @@ impl BareJid {
BareJid { inner } BareJid { inner }
} }
/// The optional node part of the JID. /// The optional node part of the JID, as a [`NodePart`]
pub fn node(&self) -> Option<&str> { pub fn node(&self) -> Option<NodePart> {
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() self.inner.node()
} }
/// The domain part of the JID. /// The domain part of the JID, as a [`DomainPart`]
pub fn domain(&self) -> &str { 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() self.inner.domain()
} }