Struct Authority

pub struct Authority { /* private fields */ }

Represents the authority component of a URI.

Implementations

impl Authority

const 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) -> &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) -> 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) -> 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) -> &str

Return a str representation of the authority

Trait Implementations

impl AsRef<str> for Authority

fn as_ref(&self) -> &str

impl Clone for Authority

fn clone(&self) -> Authority

impl Debug for Authority

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

impl Display for Authority

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

impl Eq for Authority

impl FromStr for Authority

type Err = InvalidUri;
fn from_str(s: &str) -> Result<Self, InvalidUri>

impl Hash for Authority

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

impl PartialEq for Authority

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

impl PartialEq<&str> for Authority

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

impl PartialEq<String> for Authority

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

impl PartialEq<str> for Authority

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

impl PartialOrd for Authority

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

impl PartialOrd<&str> for Authority

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

impl PartialOrd<String> for Authority

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

impl PartialOrd<str> for Authority

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

impl TryFrom<&[u8]> for Authority

type Error = InvalidUri;
fn try_from(s: &[u8]) -> Result<Self, Self::Error>

impl TryFrom<&str> for Authority

type Error = InvalidUri;
fn try_from(s: &str) -> Result<Self, Self::Error>

impl TryFrom<String> for Authority

type Error = InvalidUri;
fn try_from(t: String) -> Result<Self, Self::Error>

impl TryFrom<Vec<u8>> for Authority

type Error = InvalidUri;
fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error>

Auto Trait Implementations

impl !Freeze for Authority

impl RefUnwindSafe for Authority

impl Send for Authority

impl Sync for Authority

impl Unpin for Authority

impl UnsafeUnpin for Authority

impl UnwindSafe for Authority

Blanket Implementations

impl<T> Any for Authority where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Authority where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Authority where T: ?Sized,

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

impl<T> CloneToUninit for Authority where T: Clone,

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

impl<T> From<T> for Authority

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Authority where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for Authority where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for Authority where U: From<T>,

fn into(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<U> for Authority where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Authority where U: TryFrom<T>,

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