Crate xmpp_addr [] [src]

Implements the XMPP Address Format as defined in RFC 7622.

For historical reasons, XMPP addresses are called "Jabber Identifiers", or JIDs. JIDs are comprised of three parts: the localpart (a username or account), the domainpart (the server), and the resourcepart (a specific client) and look more or less like an email where the first two parts are demarcated by the '@' character but with the resourcepart added to the end and demarcated by the '/' character, eg:

localpart@domainpart/resourcepart

Like email, JIDs allow routing across networks based on the domainpart, and local routing based on the localpart. Unlike emails however, JIDs also allow for last-mile-delivery to specific clients (or "resources") using the resourcepart. Also unlike email, JIDs support internationalization.

Note well that this package currently isn't fully compliant with RFC 7622; it does not perform the PRECIS (RFC 7564) enforcement step and it only compiles on nightly versions of Rust.

Examples

From parts (stable)

let j = Jid::new("feste", "example.net", "")?;
assert_eq!(j, "feste@example.net");

From parts (nightly)

#![feature(try_from)]
let j: Jid = ("feste", "example.net").try_into()?;
assert_eq!(j, "feste@example.net");

let j = Jid::try_from(("feste", "example.net", "avsgasje"))?;
assert_eq!(j, "feste@example.net/avsgasje");

Parsing (stable)

let j = Jid::from_str("juliet@example.net/balcony")?;
assert_eq!(j.localpart(), Some("juliet"));
assert_eq!(j.domainpart(), "example.net");
assert_eq!(j.resourcepart(), Some("balcony"));

Parsing (nightly)

#![feature(try_from)]
let j: Jid = "orsino@example.net/ilyria".try_into()?;
assert_eq!(j, "orsino@example.net/ilyria");

let j = Jid::try_from("juliet@example.net/balcony")?;
assert_eq!(j, "juliet@example.net/balcony");

Structs

Jid

A parsed JID.

Enums

Error

Possible error values that can occur when parsing JIDs.

Type Definitions

Result

A custom result type for JIDs that elides the Error type.