pub struct Jid { /* private fields */ }Expand description
A struct representing a Jabber ID (JID).
This JID can either be “bare” (without a /resource suffix) or full (with
a resource suffix).
In many APIs, it is appropriate to use the more specific types
(BareJid or FullJid) instead, as these two JID types are generally
used in different contexts within XMPP.
This dynamic type on the other hand can be used in contexts where it is not known, at compile-time, whether a JID is full or bare.
Implementations§
Source§impl Jid
impl Jid
Sourcepub fn new(unnormalized: &str) -> Result<Jid, Error>
pub fn new(unnormalized: &str) -> Result<Jid, Error>
Constructs a Jabber ID from a string. This is of the form
node@domain/resource, where node and resource parts are optional.
If you want a non-fallible version, use Jid::from_parts instead.
§Examples
use jid::Jid;
let jid = Jid::new("node@domain/resource")?;
assert_eq!(jid.node().map(|x| x.as_str()), Some("node"));
assert_eq!(jid.domain().as_str(), "domain");
assert_eq!(jid.resource().map(|x| x.as_str()), Some("resource"));Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Returns the inner String of this JID.
Sourcepub fn from_parts(
node: Option<&NodeRef>,
domain: &DomainRef,
resource: Option<&ResourceRef>,
) -> Self
pub fn from_parts( node: Option<&NodeRef>, domain: &DomainRef, resource: Option<&ResourceRef>, ) -> Self
Build a Jid from typed parts. This method cannot fail because it uses parts that have
already been parsed and stringprepped into NodePart, DomainPart, and ResourcePart.
This method allocates and does not consume the typed parts. To avoid
allocation if both node and resource are known to be None and
domain is owned, you can use domain.into().
Sourcepub fn resource(&self) -> Option<&ResourceRef>
pub fn resource(&self) -> Option<&ResourceRef>
The optional resource of the Jabber ID. It is guaranteed to be present when the JID is
a Full variant, which you can check with Jid::is_full.
Sourcepub fn to_bare(&self) -> BareJid
pub fn to_bare(&self) -> BareJid
Allocate a new BareJid from this JID, discarding the resource.
Sourcepub fn into_bare(self) -> BareJid
pub fn into_bare(self) -> BareJid
Transforms this JID into a BareJid, throwing away the resource.
let jid: Jid = "foo@bar/baz".parse().unwrap();
let bare = jid.into_bare();
assert_eq!(bare.to_string(), "foo@bar");Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Return a reference to the canonical string representation of the JID.
Sourcepub fn try_into_full(self) -> Result<FullJid, BareJid>
pub fn try_into_full(self) -> Result<FullJid, BareJid>
Sourcepub fn try_as_full(&self) -> Result<&FullJid, &BareJid>
pub fn try_as_full(&self) -> Result<&FullJid, &BareJid>
Try to convert this Jid reference to a &FullJid if it
contains a resource and return a &BareJid otherwise.
This is useful for match blocks:
let jid: Jid = "foo@bar".parse().unwrap();
match jid.try_as_full() {
Ok(full) => println!("it is full: {:?}", full),
Err(bare) => println!("it is bare: {:?}", bare),
}Sourcepub fn try_as_full_mut(&mut self) -> Result<&mut FullJid, &mut BareJid>
pub fn try_as_full_mut(&mut self) -> Result<&mut FullJid, &mut BareJid>
Try to convert this mutable Jid reference to a
&mut FullJid if it contains a resource and return a
&mut BareJid otherwise.