Struct Authority

struct Authority { ... }

Represents the authority component of a URI.

Implementations

impl Authority

fn from_static(src: &'static str) -> Self

Attempt to convert an Authority from a static string.

This function will not perform any copying, and the string will be checked if it is empty or contains an invalid character.

Panics

This function panics if the argument contains invalid characters or is empty.

Examples

# use http::uri::Authority;
let authority = Authority::from_static("example.com");
assert_eq!(authority.host(), "example.com");
fn from_maybe_shared<T>(src: T) -> Result<Self, InvalidUri>
where
    T: AsRef<[u8]> + 'static

Attempt to convert a Bytes buffer to a Authority.

This will try to prevent a copy if the type passed is the type used internally, and will copy the data if it is not.

fn host(self: &Self) -> &str

Get the host of this Authority.

The host subcomponent of authority is identified by an IP literal encapsulated within square brackets, an IPv4 address in dotted- decimal form, or a registered name. The host subcomponent is case-insensitive.

abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
                        |---------|
                             |
                            host

Examples

# use http::uri::*;
let authority: Authority = "example.org:80".parse().unwrap();

assert_eq!(authority.host(), "example.org");
fn port(self: &Self) -> Option<Port<&str>>

Get the port part of this Authority.

The port subcomponent of authority is designated by an optional port number following the host and delimited from it by a single colon (":") character. It can be turned into a decimal port number with the as_u16 method or as a str with the as_str method.

abc://username:password@example.com:123/path/data?key=value&key2=value2#fragid1
                                    |-|
                                     |
                                    port

Examples

Authority with port

# use http::uri::Authority;
let authority: Authority = "example.org:80".parse().unwrap();

let port = authority.port().unwrap();
assert_eq!(port.as_u16(), 80);
assert_eq!(port.as_str(), "80");

Authority without port

# use http::uri::Authority;
let authority: Authority = "example.org".parse().unwrap();

assert!(authority.port().is_none());
fn port_u16(self: &Self) -> Option<u16>

Get the port of this Authority as a u16.

Example

# use http::uri::Authority;
let authority: Authority = "example.org:80".parse().unwrap();

assert_eq!(authority.port_u16(), Some(80));
fn as_str(self: &Self) -> &str

Return a str representation of the authority

impl AsRef for Authority

fn as_ref(self: &Self) -> &str

impl Clone for Authority

fn clone(self: &Self) -> Authority

impl Debug for Authority

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Display for Authority

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Eq for Authority

impl Freeze for Authority

impl FromStr for Authority

fn from_str(s: &str) -> Result<Self, InvalidUri>

impl Hash for Authority

fn hash<H>(self: &Self, state: &mut H)
where
    H: Hasher

impl PartialEq for Authority

fn eq(self: &Self, other: &str) -> bool

impl PartialEq for Authority

fn eq(self: &Self, other: &Authority) -> bool

impl PartialEq for Authority

fn eq(self: &Self, other: &String) -> bool

impl PartialOrd for Authority

fn partial_cmp(self: &Self, other: &Authority) -> Option<Ordering>

impl PartialOrd for Authority

fn partial_cmp(self: &Self, other: &String) -> Option<Ordering>

impl PartialOrd for Authority

fn partial_cmp(self: &Self, other: &str) -> Option<Ordering>

impl RefUnwindSafe for Authority

impl Send for Authority

impl Sync for Authority

impl TryFrom for Authority

fn try_from(vec: Vec<u8>) -> Result<Self, <Self as >::Error>

impl TryFrom for Authority

fn try_from(t: String) -> Result<Self, <Self as >::Error>

impl Unpin for Authority

impl UnsafeUnpin for Authority

impl UnwindSafe for Authority

impl<'a> PartialEq for Authority

fn eq(self: &Self, other: &&'a str) -> bool

impl<'a> PartialOrd for Authority

fn partial_cmp(self: &Self, other: &&'a str) -> Option<Ordering>

impl<'a> TryFrom for Authority

fn try_from(s: &'a [u8]) -> Result<Self, <Self as >::Error>

impl<'a> TryFrom for Authority

fn try_from(s: &'a str) -> Result<Self, <Self as >::Error>

impl<T> Any for Authority

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Authority

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Authority

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Authority

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Authority

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Authority

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for Authority

fn to_string(self: &Self) -> String

impl<T, U> Into for Authority

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Authority

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Authority

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>