[−][src]Struct uriparse::authority::Authority
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]
pub fn as_borrowed(&self) -> Authority
[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>,
[src]
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]
Returns whether 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!(authority.has_password());
pub fn has_port(&self) -> bool
[src]
Returns whether there is a password in the authority as defined in [RFC3986, Section 3.2.1].
Examples
use std::convert::TryFrom; use uriparse::Authority; let authority = Authority::try_from("example.com:8080").unwrap(); assert!(authority.has_port());
pub fn has_username(&self) -> bool
[src]
Returns whether 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!(authority.has_username());
pub fn host(&self) -> &Host<'authority>
[src]
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]
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]
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 is_normalized(&self) -> bool
[src]
Returns whether the authority is normalized.
A normalized authority will have all of its sub-components normalized.
This function runs in constant-time.
Examples
use std::convert::TryFrom; use uriparse::Authority; let authority = Authority::try_from("username:password@example.com").unwrap(); assert!(authority.is_normalized()); let mut authority = Authority::try_from("username:p%61ssword@EXAMPLE.COM").unwrap(); assert!(!authority.is_normalized()); authority.normalize(); assert!(authority.is_normalized());
pub fn map_host<Mapper>(&mut self, mapper: Mapper) -> &Host<'authority> where
Mapper: FnOnce(Host<'authority>) -> Host<'authority>,
[src]
Mapper: FnOnce(Host<'authority>) -> Host<'authority>,
Maps the host using the given map function.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Host}; let mut authority = Authority::try_from("example.com").unwrap(); authority.map_host(|_| Host::try_from("127.0.0.1").unwrap()); assert_eq!(authority.to_string(), "127.0.0.1");
pub fn map_password<Mapper>(
&mut self,
mapper: Mapper
) -> Option<&Password<'authority>> where
Mapper: FnOnce(Option<Password<'authority>>) -> Option<Password<'authority>>,
[src]
&mut self,
mapper: Mapper
) -> Option<&Password<'authority>> where
Mapper: FnOnce(Option<Password<'authority>>) -> Option<Password<'authority>>,
Maps the password using the given map function.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Password}; let mut authority = Authority::try_from("example.com").unwrap(); authority.map_password(|_| Some(Password::try_from("password").unwrap())); assert_eq!(authority.to_string(), ":password@example.com");
pub fn map_port<Mapper>(&mut self, mapper: Mapper) -> Option<u16> where
Mapper: FnOnce(Option<u16>) -> Option<u16>,
[src]
Mapper: FnOnce(Option<u16>) -> Option<u16>,
Maps the port using the given map function.
Examples
use std::convert::TryFrom; use uriparse::Authority; let mut authority = Authority::try_from("example.com").unwrap(); authority.map_port(|_| Some(8080)); assert_eq!(authority.to_string(), "example.com:8080");
pub fn map_username<Mapper>(
&mut self,
mapper: Mapper
) -> Option<&Username<'authority>> where
Mapper: FnOnce(Option<Username<'authority>>) -> Option<Username<'authority>>,
[src]
&mut self,
mapper: Mapper
) -> Option<&Username<'authority>> where
Mapper: FnOnce(Option<Username<'authority>>) -> Option<Username<'authority>>,
Maps the username using the given map function.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Username}; let mut authority = Authority::try_from("example.com").unwrap(); authority.map_username(|_| Some(Username::try_from("username").unwrap())); assert_eq!(authority.to_string(), "username@example.com");
pub fn normalize(&mut self)
[src]
Normalizes the authority.
A normalized authority will have all of its sub-components normalized.
Examples
use std::convert::TryFrom; use uriparse::Authority; let mut authority = Authority::try_from("username:password@example.com").unwrap(); authority.normalize(); assert_eq!(authority.to_string(), "username:password@example.com"); let mut authority = Authority::try_from("username:p%61ssword@EXAMPLE.COM").unwrap(); assert_eq!(authority.to_string(), "username:p%61ssword@EXAMPLE.COM"); authority.normalize(); assert_eq!(authority.to_string(), "username:password@example.com");
pub fn password(&self) -> Option<&Password<'authority>>
[src]
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]
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 set_host<HostType, HostError>(
&mut self,
host: HostType
) -> Result<&Host<'authority>, InvalidAuthority> where
Host<'authority>: TryFrom<HostType, Error = HostError>,
InvalidAuthority: From<HostError>,
[src]
&mut self,
host: HostType
) -> Result<&Host<'authority>, InvalidAuthority> where
Host<'authority>: TryFrom<HostType, Error = HostError>,
InvalidAuthority: From<HostError>,
Sets the host of the authority.
An error will be returned if the conversion to a Host
fails.
Examples
use std::convert::TryFrom; use std::net::Ipv6Addr; use uriparse::{Authority, Host}; let mut authority = Authority::try_from("example.com:8080").unwrap(); authority.set_host("127.0.0.1"); assert_eq!(authority.to_string(), "127.0.0.1:8080"); authority.set_host(Host::IPv6Address("::1".parse().unwrap())); assert_eq!(authority.to_string(), "[::1]:8080");
pub fn set_password<PasswordType, PasswordError>(
&mut self,
password: Option<PasswordType>
) -> Result<Option<&Password<'authority>>, InvalidAuthority> where
Password<'authority>: TryFrom<PasswordType, Error = PasswordError>,
InvalidAuthority: From<PasswordError>,
[src]
&mut self,
password: Option<PasswordType>
) -> Result<Option<&Password<'authority>>, InvalidAuthority> where
Password<'authority>: TryFrom<PasswordType, Error = PasswordError>,
InvalidAuthority: From<PasswordError>,
Sets the password of the authority.
An error will be returned if the conversion to a Password
fails.
If the given password is not None
, then the username will be set to ""
if it is
currently not set.
Examples
use std::convert::TryFrom; use uriparse::Authority; let mut authority = Authority::try_from("example.com").unwrap(); authority.set_password(Some("secret")); assert_eq!(authority.to_string(), ":secret@example.com");
pub fn set_port(&mut self, port: Option<u16>) -> Option<u16>
[src]
Sets the port of the authority.
Examples
use std::convert::TryFrom; use uriparse::Authority; let mut authority = Authority::try_from("example.com").unwrap(); authority.set_port(Some(8080)); assert_eq!(authority.to_string(), "example.com:8080");
pub fn set_username<UsernameType, UsernameError>(
&mut self,
username: Option<UsernameType>
) -> Result<Option<&Username<'authority>>, InvalidAuthority> where
Username<'authority>: TryFrom<UsernameType, Error = UsernameError>,
InvalidAuthority: From<UsernameError>,
[src]
&mut self,
username: Option<UsernameType>
) -> Result<Option<&Username<'authority>>, InvalidAuthority> where
Username<'authority>: TryFrom<UsernameType, Error = UsernameError>,
InvalidAuthority: From<UsernameError>,
Sets the username of the authority.
An error will be returned if the conversion to a Username
fails.
If the given username is None
, this will also remove any set password.
Examples
use std::convert::TryFrom; use uriparse::{Authority, Username}; let mut authority = Authority::try_from("example.com").unwrap(); authority.set_username(Some("myname")); assert_eq!(authority.to_string(), "myname@example.com"); let mut authority = Authority::try_from("user:pass@example.com").unwrap(); authority.set_username(None::<Username>); assert_eq!(authority.to_string(), "example.com");
pub fn username(&self) -> Option<&Username<'authority>>
[src]
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> PartialEq<Authority<'authority>> for Authority<'authority>
[src]
fn eq(&self, other: &Authority<'authority>) -> bool
[src]
fn ne(&self, other: &Authority<'authority>) -> bool
[src]
impl<'authority> From<Authority<'authority>> for String
[src]
impl<'authority> Clone for Authority<'authority>
[src]
fn clone(&self) -> Authority<'authority>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'authority> Eq for Authority<'authority>
[src]
impl<'_> Display for Authority<'_>
[src]
impl<'authority> Debug for Authority<'authority>
[src]
impl<'authority> Hash for Authority<'authority>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<'authority> TryFrom<&'authority [u8]> for Authority<'authority>
[src]
type Error = InvalidAuthority
The type returned in the event of a conversion error.
fn try_from(value: &'authority [u8]) -> Result<Self, Self::Error>
[src]
impl<'authority> TryFrom<&'authority str> for Authority<'authority>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
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]
T: 'static + ?Sized,