From 393feb8d5e27aa6977fa277d27a0912937c44a01 Mon Sep 17 00:00:00 2001 From: Link Mauve Date: Sun, 7 Jun 2026 19:54:19 +0200 Subject: [PATCH] jid: Add a failible DomainRef::with_node_str() This matches BareJid::with_resource_str() in that it allows the user to parse a &str into a NodePart and construct the BareJid in one call. --- jid/CHANGELOG.md | 5 +++++ jid/src/parts.rs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/jid/CHANGELOG.md b/jid/CHANGELOG.md index be65d621..a02642b3 100644 --- a/jid/CHANGELOG.md +++ b/jid/CHANGELOG.md @@ -1,3 +1,8 @@ +Version NEXT, release XXXX-XX-XX: + * Changes: + - Add a `DomainRef::with_node_str()` method, matching `with_resource_str()` + but for `with_node()`. + Version 0.12.2, release 2025-02-26: * Changes: - Add a `NodeRef::unescape()` method, to implement XEP-0106 escaping. diff --git a/jid/src/parts.rs b/jid/src/parts.rs index cb1a4baa..689ee8c0 100644 --- a/jid/src/parts.rs +++ b/jid/src/parts.rs @@ -288,6 +288,14 @@ impl DomainRef { pub fn with_node(&self, node: &NodeRef) -> BareJid { BareJid::from_parts(Some(node), self) } + + /// Construct a bare JID (a JID without a resource) from this domain and + /// the given node (local part), by specifying a stringy `node`. + /// If your node has already been parsed into a [`NodePart`], use [`DomainRef::with_node`]. + pub fn with_node_str(&self, node: &str) -> Result { + let node = NodePart::new(node)?; + Ok(self.with_node(&node)) + } } impl From for BareJid {