[−][src]Struct xmpp_addr::Jid
A parsed JID.
Methods
impl<'a> Jid<'a>
[src]
impl<'a> Jid<'a>
pub fn split(s: &'a str) -> Result<(Option<&'a str>, &'a str, Option<&'a str>)> | [src] |
Splits a JID formatted as a string into its localpart, domainpart, and resourcepart. The localpart and resourcepart are optional, but the domainpart is always returned.
Errors
This function performs a "naive" string split and does not perform any validation of the
individual parts other than to make sure that required parts exist. For example
"@example.com" will return an error (EmptyLocal
), but "%@example.com" will not (even
though "%" is not a valid localpart). The length of localparts and resourceparts is also
not checked (other than if they're empty). This is because when creating an actual JID it
is possible for certain Unicode characters to be canonicalized into a shorter length
encoding, meaning that a part that was previously too long may suddenly fit in the maximum
length. ShortDomain
may be returned because we know that domains will never become
longer after performing IDNA2008 operations, but LongDomain
may not be returned for the
same reasons as mentioned above.
Possible errors include:
EmptyJid
(eg.""
)EmptyLocal
("@example.com"
)EmptyResource
("example.com/"
)ShortDomain
("a"
,"foo@/bar"
)
Examples
Basic usage:
let (lp, dp, rp) = Jid::split("feste@example.net")?; assert_eq!(lp, Some("feste")); assert_eq!(dp, "example.net"); assert_eq!(rp, None);
pub fn new<L, R>(local: L, domain: &'a str, resource: R) -> Result<Jid<'a>> where | [src] |
Constructs a JID from its constituent parts. The localpart is generally the username of a user on a particular server, the domainpart is a domain, hostname, or IP address where the user or entity resides, and the resourcepart identifies a specific client. Everything but the domain is optional.
Errors
If the localpart or resourcepart passed to this function is not valid, or the domainpart fails IDNA processing or is not a valid IPv6 address, this function returns an error variant.
Examples
Basic usage:
let j = Jid::new("feste", "example.net", None)?; assert_eq!(j, "feste@example.net");
pub fn from_domain(domain: &'a str) -> Result<Jid<'a>> | [src] |
Construct a JID containing only a domain part.
Errors
If domain fails the IDNA "to Unicode" operation, or is enclosed in square brackets ("[]") but is not a valid IPv6 address, this function returns an error variant.
Examples
Basic usage:
let j = Jid::from_domain("example.net")?; assert_eq!(j, "example.net");
pub fn bare(self) -> Jid<'a> | [src] |
Consumes a JID to construct a bare JID (a JID without a resourcepart).
Examples
Basic usage:
let j = Jid::new("feste", "example.net", "res")?; assert_eq!(j.bare(), "feste@example.net");
pub fn domain(self) -> Jid<'a> | [src] |
Consumes a JID to construct a JID with only the domainpart.
Examples
Basic usage:
let j = Jid::new("feste", "example.net", "res")?; assert_eq!(j.domain(), "example.net");
pub fn with_local<T: Into<Option<&'a str>>>(self, local: T) -> Result<Jid<'a>> | [src] |
Consumes a JID to construct a new JID with the given localpart.
Errors
If the localpart is too long Error::LongLocal
is returned.
Examples
Basic usage:
let j = Jid::from_str("example.net")?; assert_eq!(j.with_local("feste")?, "feste@example.net"); let j = Jid::from_str("iago@example.net")?; assert_eq!(j.with_local(None)?, "example.net"); let j = Jid::from_str("feste@example.net")?; assert!(j.with_local("").is_err());
pub fn with_domain(self, domain: &'a str) -> Result<Jid<'a>> | [src] |
Consumes a JID to construct a new JID with the given domainpart.
Errors
If the domain is too long, too short, or fails IDNA processing, an error variant is returned.
Examples
Basic usage:
let j = Jid::from_str("feste@example.net")?; assert_eq!(j.with_domain("example.org")?, "feste@example.org");
pub fn with_resource<T: Into<Option<&'a str>>>( | [src] |
Consumes a JID to construct a new JID with the given resourcepart.
Errors
If the resource is too long Error::LongResource
is returned.
Examples
Basic usage:
let j = Jid::from_str("feste@example.net")?; assert_eq!(j.with_resource("1234")?, "feste@example.net/1234"); let j = Jid::from_str("feste@example.net/1234")?; assert_eq!(j.with_resource(None)?, "feste@example.net"); let j = Jid::from_str("feste@example.net")?; assert!(j.with_resource("").is_err());
pub fn from_str(s: &'a str) -> Result<Jid<'a>> | [src] |
Parse a string to create a Jid.
This does not implement the FromStr
trait because the Jid type requires an explicit
lifetime annotation and the from_str
method of FromStr
uses an implicit annotation
which is not compatible with the Jid type.
Errors
If the entire string or any part of the JID is empty or not valid, or the domainpart fails IDNA processing or is not a valid IPv6 address, this function returns an error variant.
Examples
let j = Jid::from_str("juliet@example.net/balcony")?; assert_eq!(j, "juliet@example.net/balcony");
pub fn localpart(&self) -> Option<&str> | [src] |
Returns the localpart of the JID in canonical form.
Examples
let j = Jid::from_str("mercutio@example.net/rp")?; assert_eq!(j.localpart(), Some("mercutio")); let j = Jid::from_str("example.net/rp")?; assert!(j.localpart().is_none());
pub fn domainpart(&self) -> &str | [src] |
Returns the domainpart of the JID in canonical form.
Examples
let j = Jid::from_str("mercutio@example.net/rp")?; assert_eq!(j.domainpart(), "example.net");
pub fn resourcepart(&self) -> Option<&str> | [src] |
Returns the resourcepart of the JID in canonical form.
Examples
let j = Jid::from_str("example.net/rp")?; assert_eq!(j.resourcepart(), Some("rp")); let j = Jid::from_str("feste@example.net")?; assert!(j.resourcepart().is_none());
pub unsafe fn new_unchecked<L, R>( | [src] |
Constructs a JID from its constituent parts, bypassing safety checks.
A None
value for the localpart or resourcepart indicates that there is no localpart or
resourcepart. A value of Some("")
(although note that the Some()
wrapper may be elided)
indicates that the localpart or resourcepart is empty, which is invalid, but allowed by
this unsafe function (eg. @example.com
).
Examples
Constructing an invalid JID:
unsafe { let j = Jid::new_unchecked(r#"/o\"#, "[badip]", None); assert_eq!(j.localpart(), Some(r#"/o\"#)); assert_eq!(j.domainpart(), "[badip]"); assert_eq!(j.resourcepart(), None); // Note that comparisons you would expect to work may fail when creating unsafe JIDs. assert_ne!(j, r#"/o\@[badip]"#); let j = Jid::new_unchecked("", "example.com", ""); assert_eq!(j, "@example.com/"); }
Trait Implementations
impl<'a> From<Ipv4Addr> for Jid<'a>
[src]
impl<'a> From<Ipv4Addr> for Jid<'a>
Creates a JID from an IPv4 address.
impl<'a> From<Ipv6Addr> for Jid<'a>
[src]
impl<'a> From<Ipv6Addr> for Jid<'a>
Creates a JID from an IPv6 address.
impl<'a> From<IpAddr> for Jid<'a>
[src]
impl<'a> From<IpAddr> for Jid<'a>
Creates a JID from an IP address.
impl<'a> Eq for Jid<'a>
[src]
impl<'a> Eq for Jid<'a>
impl<'a> PartialOrd<Jid<'a>> for Jid<'a>
[src]
impl<'a> PartialOrd<Jid<'a>> for Jid<'a>
fn partial_cmp(&self, other: &Jid<'a>) -> Option<Ordering> | [src] |
fn lt(&self, other: &Jid<'a>) -> bool | [src] |
fn le(&self, other: &Jid<'a>) -> bool | [src] |
fn gt(&self, other: &Jid<'a>) -> bool | [src] |
fn ge(&self, other: &Jid<'a>) -> bool | [src] |
impl<'a> PartialEq<Jid<'a>> for Jid<'a>
[src]
impl<'a> PartialEq<Jid<'a>> for Jid<'a>
impl<'_> PartialEq<str> for Jid<'_>
[src]
impl<'_> PartialEq<str> for Jid<'_>
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part is
compared with its corresponding part in the JID. If this comparison is successful, true is
returned and the comparison is cheap. If this does not match, however, the string is then
canonicalized (by converting it into a JID) and the parts are compared again; this may require
expensive heap allocations. If constructing a JID from the string fails, the comparison always
fails (even if the original JID is would match the invalid output). Comparisons involving
unsafe JIDs constructed with Jid::new_unchecked
should construct an unsafe JID from the
string and manually compare the parts.
Examples
let j = Jid::from_str("example.net/rp")?; assert!(j == "example.net/rp");
fn eq(&self, other: &str) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'_> PartialEq<Jid<'_>> for str
[src]
impl<'_> PartialEq<Jid<'_>> for str
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part is
compared with its corresponding part in the JID. If this comparison is successful, true is
returned and the comparison is cheap. If this does not match, however, the string is then
canonicalized (by converting it into a JID) and the parts are compared again; this may require
expensive heap allocations. If constructing a JID from the string fails, the comparison always
fails (even if the original JID is would match the invalid output). Comparisons involving
unsafe JIDs constructed with Jid::new_unchecked
should construct an unsafe JID from the
string and manually compare the parts.
Examples
let j = Jid::from_str("example.net/rp")?; assert!("example.net/rp" == j);
fn eq(&self, other: &Jid) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a, 'b> PartialEq<Cow<'b, str>> for Jid<'a>
[src]
impl<'a, 'b> PartialEq<Cow<'b, str>> for Jid<'a>
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part
is compared with its corresponding part in the JID. If this comparison is successful,
true is returned and the comparison is cheap. If this does not match, however, the
string is then canonicalized (by converting it into a JID) and the parts are compared
again; this may require expensive heap allocations. If constructing a JID from the
string fails, the comparison always fails (even if the original JID is would match the
invalid output). Comparisons involving unsafe JIDs constructed with
Jid::new_unchecked
should construct an unsafe JID from the string and manually
compare the parts.
fn eq(&self, other: &Cow<'b, str>) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a, 'b> PartialEq<Jid<'a>> for Cow<'b, str>
[src]
impl<'a, 'b> PartialEq<Jid<'a>> for Cow<'b, str>
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part
is compared with its corresponding part in the JID. If this comparison is successful,
true is returned and the comparison is cheap. If this does not match, however, the
string is then canonicalized (by converting it into a JID) and the parts are compared
again; this may require expensive heap allocations. If constructing a JID from the
string fails, the comparison always fails (even if the original JID is would match the
invalid output). Comparisons involving unsafe JIDs constructed with
Jid::new_unchecked
should construct an unsafe JID from the string and manually
compare the parts.
fn eq(&self, other: &Jid<'a>) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a, 'b> PartialEq<&'b str> for Jid<'a>
[src]
impl<'a, 'b> PartialEq<&'b str> for Jid<'a>
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part
is compared with its corresponding part in the JID. If this comparison is successful,
true is returned and the comparison is cheap. If this does not match, however, the
string is then canonicalized (by converting it into a JID) and the parts are compared
again; this may require expensive heap allocations. If constructing a JID from the
string fails, the comparison always fails (even if the original JID is would match the
invalid output). Comparisons involving unsafe JIDs constructed with
Jid::new_unchecked
should construct an unsafe JID from the string and manually
compare the parts.
fn eq(&self, other: &&'b str) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a, 'b> PartialEq<Jid<'a>> for &'b str
[src]
impl<'a, 'b> PartialEq<Jid<'a>> for &'b str
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part
is compared with its corresponding part in the JID. If this comparison is successful,
true is returned and the comparison is cheap. If this does not match, however, the
string is then canonicalized (by converting it into a JID) and the parts are compared
again; this may require expensive heap allocations. If constructing a JID from the
string fails, the comparison always fails (even if the original JID is would match the
invalid output). Comparisons involving unsafe JIDs constructed with
Jid::new_unchecked
should construct an unsafe JID from the string and manually
compare the parts.
fn eq(&self, other: &Jid<'a>) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a, 'b> PartialEq<String> for Jid<'a>
[src]
impl<'a, 'b> PartialEq<String> for Jid<'a>
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part
is compared with its corresponding part in the JID. If this comparison is successful,
true is returned and the comparison is cheap. If this does not match, however, the
string is then canonicalized (by converting it into a JID) and the parts are compared
again; this may require expensive heap allocations. If constructing a JID from the
string fails, the comparison always fails (even if the original JID is would match the
invalid output). Comparisons involving unsafe JIDs constructed with
Jid::new_unchecked
should construct an unsafe JID from the string and manually
compare the parts.
fn eq(&self, other: &String) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a, 'b> PartialEq<Jid<'a>> for String
[src]
impl<'a, 'b> PartialEq<Jid<'a>> for String
Allows JIDs to be compared with strings.
This may be expensive. The string is first split using Jid::split
and each part
is compared with its corresponding part in the JID. If this comparison is successful,
true is returned and the comparison is cheap. If this does not match, however, the
string is then canonicalized (by converting it into a JID) and the parts are compared
again; this may require expensive heap allocations. If constructing a JID from the
string fails, the comparison always fails (even if the original JID is would match the
invalid output). Comparisons involving unsafe JIDs constructed with
Jid::new_unchecked
should construct an unsafe JID from the string and manually
compare the parts.
fn eq(&self, other: &Jid<'a>) -> bool | [src] |
| 1.0.0 [src] |
This method tests for !=
.
impl<'a> Clone for Jid<'a>
[src]
impl<'a> Clone for Jid<'a>
fn clone(&self) -> Jid<'a> | [src] |
fn clone_from(&mut self, source: &Self) | 1.0.0 [src] |
Performs copy-assignment from source
. Read more
impl<'a> Ord for Jid<'a>
[src]
impl<'a> Ord for Jid<'a>
fn cmp(&self, other: &Jid<'a>) -> Ordering | [src] |
fn max(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self | 1.21.0 [src] |
Compares and returns the minimum of two values. Read more
impl<'a> Debug for Jid<'a>
[src]
impl<'a> Debug for Jid<'a>
impl<'_> Display for Jid<'_>
[src]
impl<'_> Display for Jid<'_>
Format the JID in its canonical string form.
Examples
Formatting and printing:
let j = Jid::from_str("viola@example.net")?; assert_eq!(format!("{}", j), "viola@example.net");
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error> | [src] |
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |