From 072cba6a3ed6389886fcd87ff9ec71eb8f9ab524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 12 Jun 2017 17:40:39 +0100 Subject: [PATCH] Add get_ functions that return new truncated structs from the current one --- src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b78001b0..323c43f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,6 +190,28 @@ impl Jid { } } + /// Returns a new Jabber ID from the current one with only node and domain. + /// + /// This is of the form `node`@`domain`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::full("node", "domain", "resource").get_bare(); + /// + /// assert_eq!(jid.node, Some("node".to_owned())); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, None); + pub fn get_bare(self) -> Jid { + Jid { + node: self.node.clone(), + domain: self.domain.clone(), + resource: None, + } + } + /// Constructs a Jabber ID containing only a `domain`. /// /// This is of the form `domain`. @@ -214,6 +236,28 @@ impl Jid { } } + /// Returns a new Jabber ID from the current one with only domain. + /// + /// This is of the form `domain`. + /// + /// # Examples + /// + /// ``` + /// use jid::Jid; + /// + /// let jid = Jid::full("node", "domain", "resource").get_domain(); + /// + /// assert_eq!(jid.node, None); + /// assert_eq!(jid.domain, "domain".to_owned()); + /// assert_eq!(jid.resource, None); + pub fn get_domain(self) -> Jid { + Jid { + node: None, + domain: self.domain.clone(), + resource: None, + } + } + /// Constructs a Jabber ID containing the `domain` and `resource` components. /// /// This is of the form `domain`/`resource`.