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]
impl<'authority> Authority<'authority>
pub fn from_parts<'new_authority, UsernameType, PasswordType, HostType, UsernameError, PasswordError, HostError>(
username: Option<UsernameType>,
password: Option<PasswordType>,
host: HostType,
port: Option<u16>
) -> Result<Authority<'new_authority>, InvalidAuthority> where
Username<'new_authority>: TryFrom<UsernameType, Error = UsernameError>,
Password<'new_authority>: TryFrom<PasswordType, Error = PasswordError>,
Host<'new_authority>: TryFrom<HostType, Error = HostError>,
InvalidAuthority: From<UsernameError> + From<PasswordError> + From<HostError>,
[src]
pub fn from_parts<'new_authority, UsernameType, PasswordType, HostType, UsernameError, PasswordError, HostError>(
username: Option<UsernameType>,
password: Option<PasswordType>,
host: HostType,
port: Option<u16>
) -> Result<Authority<'new_authority>, InvalidAuthority> where
Username<'new_authority>: TryFrom<UsernameType, Error = UsernameError>,
Password<'new_authority>: TryFrom<PasswordType, Error = PasswordError>,
Host<'new_authority>: TryFrom<HostType, Error = HostError>,
InvalidAuthority: From<UsernameError> + From<PasswordError> + From<HostError>,
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");
pub fn has_password(&self) -> bool
[src]
pub fn has_password(&self) -> bool
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);
pub fn has_username(&self) -> bool
[src]
pub fn has_username(&self) -> bool
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);
pub fn host(&self) -> &Host<'authority>
[src]
pub fn host(&self) -> &Host<'authority>
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");
pub fn into_owned(self) -> Authority<'static>
[src]
pub fn into_owned(self) -> Authority<'static>
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.
pub fn into_parts(
self
) -> (Option<Username<'authority>>, Option<Password<'authority>>, Host<'authority>, Option<u16>)
[src]
pub fn into_parts(
self
) -> (Option<Username<'authority>>, Option<Password<'authority>>, Host<'authority>, Option<u16>)
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);
pub fn password(&self) -> Option<&Password<'authority>>
[src]
pub fn password(&self) -> Option<&Password<'authority>>
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");
pub fn port(&self) -> Option<u16>
[src]
pub fn port(&self) -> Option<u16>
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);
pub fn username(&self) -> Option<&Username<'authority>>
[src]
pub fn username(&self) -> Option<&Username<'authority>>
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]
impl<'authority> Clone for Authority<'authority>
fn clone(&self) -> Authority<'authority>
[src]
fn clone(&self) -> Authority<'authority>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<'authority> Debug for Authority<'authority>
[src]
impl<'authority> Debug for Authority<'authority>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'authority> Eq for Authority<'authority>
[src]
impl<'authority> Eq for Authority<'authority>
impl<'authority> Hash for Authority<'authority>
[src]
impl<'authority> Hash for Authority<'authority>
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'authority> PartialEq for Authority<'authority>
[src]
impl<'authority> PartialEq for Authority<'authority>
fn eq(&self, other: &Authority<'authority>) -> bool
[src]
fn eq(&self, other: &Authority<'authority>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Authority<'authority>) -> bool
[src]
fn ne(&self, other: &Authority<'authority>) -> bool
This method tests for !=
.
impl<'authority> Display for Authority<'authority>
[src]
impl<'authority> Display for Authority<'authority>
fn fmt(&self, formatter: &mut Formatter) -> Result
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'authority> From<Authority<'authority>> for String
[src]
impl<'authority> From<Authority<'authority>> for String
impl<'authority> TryFrom<&'authority [u8]> for Authority<'authority>
[src]
impl<'authority> TryFrom<&'authority [u8]> for Authority<'authority>
type Error = InvalidAuthority
try_from
)The type returned in the event of a conversion error.
fn try_from(value: &'authority [u8]) -> Result<Self, Self::Error>
[src]
fn try_from(value: &'authority [u8]) -> Result<Self, Self::Error>
try_from
)Performs the conversion.
impl<'authority> TryFrom<&'authority str> for Authority<'authority>
[src]
impl<'authority> TryFrom<&'authority str> for Authority<'authority>