Struct uriparse::authority::Authority[][src]

pub struct Authority<'authority> { /* fields omitted */ }

The authority component as defined in [RFC3986, Section 3.2].

Any conversions to a string will not hide the password component of the authority. Be careful if you decide to perform logging.

Methods

impl<'authority> Authority<'authority>
[src]

Constructs a new Authority from the individual parts: username, password, host, and port.

The lifetime used by the resulting value will be the lifetime of the part that is most restricted in scope.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::from_parts(
    Some("username"),
    Some("password"),
    "example.com",
    Some(80)
).unwrap();
assert_eq!(authority.to_string(), "username:password@example.com:80");

Returns whether or not there is a password in the authority as defined in [RFC3986, Section 3.2.1].

There will only be a password if the URI has a user information component and the component contains the ':' delimiter.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("username:password@example.com").unwrap();
assert_eq!(authority.has_password(), true);

Returns whether or not there is a username in the authority as defined in [RFC3986, Section 3.2.1].

There will always be a username as long as there is a '@' delimiter present in the authority.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("username@example.com").unwrap();
assert_eq!(authority.has_username(), true);

The host component of the authority as defined in [RFC3986, Section 3.2.2].

An authority component always has a host, though it may be an empty registered name.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("username:password@example.com").unwrap();
assert_eq!(authority.host().to_string().as_str(), "example.com");

Converts the Authority into an owned copy.

If you construct the authority from a source with a non-static lifetime, you may run into lifetime problems due to the way the struct is designed. Calling this function will ensure that the returned value has a static lifetime.

This is different from just cloning. Cloning the authority will just copy the eferences, and thus the lifetime will remain the same.

Consumes the Authority and returns its parts: username, password, host, and port.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("username:password@example.com:80").unwrap();
let (username, password, host, port) = authority.into_parts();

assert_eq!(username.unwrap(), "username");
assert_eq!(password.unwrap(), "password");
assert_eq!(host.to_string(), "example.com");
assert_eq!(port.unwrap(), 80);

The password component of the authority as defined in [RFC3986, Section 3.2.1].

The password will be None if the user information component of the authority did not contain a ':'. Otherwise, it will be whatever is after the ':' until the '@' character. It may be empty as well.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("username:password@example.com").unwrap();
assert_eq!(authority.password().unwrap(), "password");

The port component of the authority as defined in [RFC3986, Section 3.2.3].

The port will be None if a port was not specified.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("example.com:80").unwrap();
assert_eq!(authority.port().unwrap(), 80);

The username component of the authority as defined in [RFC3986, Section 3.2.1].

The username will be None if the user information component of the authority did not contain a ':'. Otherwise, it will be whatever is after the ':' until the '@' character. It may be empty as well.

Examples

use std::convert::TryFrom;

use uriparse::Authority;

let authority = Authority::try_from("username:password@example.com").unwrap();
assert_eq!(authority.password().unwrap(), "password");

Trait Implementations

impl<'authority> Clone for Authority<'authority>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'authority> Debug for Authority<'authority>
[src]

Formats the value using the given formatter. Read more

impl<'authority> Eq for Authority<'authority>
[src]

impl<'authority> Hash for Authority<'authority>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<'authority> PartialEq for Authority<'authority>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'authority> Display for Authority<'authority>
[src]

Formats the value using the given formatter. Read more

impl<'authority> From<Authority<'authority>> for String
[src]

Performs the conversion.

impl<'authority> TryFrom<&'authority [u8]> for Authority<'authority>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<'authority> TryFrom<&'authority str> for Authority<'authority>
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

Auto Trait Implementations

impl<'authority> Send for Authority<'authority>

impl<'authority> Sync for Authority<'authority>