Struct rocket::http::uri::Authority

pub struct Authority<'a> { /* private fields */ }
Expand description

A URI with an authority only: user:pass@host:8000.

Structure

The following diagram illustrates the syntactic structure of an authority URI:

username:password@some.host:8088
|---------------| |-------| |--|
    user info        host   port

Only the host part of the URI is required.

(De)serialization

Authority is both Serialize and Deserialize:

use serde::{Serialize, Deserialize};
use rocket::http::uri::Authority;

#[derive(Deserialize, Serialize)]
struct UriOwned {
    uri: Authority<'static>,
}

#[derive(Deserialize, Serialize)]
struct UriBorrowed<'a> {
    uri: Authority<'a>,
}

Implementations§

§

impl<'a> Authority<'a>

pub fn parse(string: &'a str) -> Result<Authority<'a>, Error<'a>>

Parses the string string into an Authority. Parsing will never allocate. Returns an Error if string is not a valid authority URI.

Example
use rocket::http::uri::Authority;

// Parse a valid authority URI.
let uri = Authority::parse("user:pass@host").expect("valid URI");
assert_eq!(uri.user_info(), Some("user:pass"));
assert_eq!(uri.host(), "host");
assert_eq!(uri.port(), None);

// Invalid authority URIs fail to parse.
Authority::parse("https://rocket.rs").expect_err("invalid authority");

// Prefer to use `uri!()` when the input is statically known:
let uri = uri!("user:pass@host");
assert_eq!(uri.user_info(), Some("user:pass"));
assert_eq!(uri.host(), "host");
assert_eq!(uri.port(), None);

pub fn parse_owned(string: String) -> Result<Authority<'static>, Error<'static>>

Parses the string string into an Authority. Parsing never allocates on success. May allocate on error.

This method should be used instead of Authority::parse() when the source URI is already a String. Returns an Error if string is not a valid authority URI.

Example
use rocket::http::uri::Authority;

let source = format!("rocket.rs:8000");
let uri = Authority::parse_owned(source).expect("valid URI");
assert!(uri.user_info().is_none());
assert_eq!(uri.host(), "rocket.rs");
assert_eq!(uri.port(), Some(8000));

pub fn user_info(&self) -> Option<&str>

Returns the user info part of the authority URI, if there is one.

Example
let uri = uri!("username:password@host");
assert_eq!(uri.user_info(), Some("username:password"));

pub fn host(&self) -> &str

Returns the host part of the authority URI.

Example
let uri = uri!("domain.com:123");
assert_eq!(uri.host(), "domain.com");

let uri = uri!("username:password@host:123");
assert_eq!(uri.host(), "host");

let uri = uri!("username:password@[1::2]:123");
assert_eq!(uri.host(), "[1::2]");

pub fn port(&self) -> Option<u16>

Returns the port part of the authority URI, if there is one.

Example
// With a port.
let uri = uri!("username:password@host:123");
assert_eq!(uri.port(), Some(123));

let uri = uri!("domain.com:8181");
assert_eq!(uri.port(), Some(8181));

// Without a port.
let uri = uri!("username:password@host");
assert_eq!(uri.port(), None);

Trait Implementations§

§

impl<'a> Clone for Authority<'a>

§

fn clone(&self) -> Authority<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a> Debug for Authority<'a>

§

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

Formats the value using the given formatter. Read more
§

impl<'a, 'de> Deserialize<'de> for Authority<'a>

§

fn deserialize<D>( deserializer: D ) -> Result<Authority<'a>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Authority<'_>

§

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

Formats the value using the given formatter. Read more
§

impl<'a> From<Authority<'a>> for Host<'a>

§

fn from(auth: Authority<'a>) -> Host<'a>

Converts to this type from the input type.
§

impl<'a> From<Authority<'a>> for Reference<'a>

§

fn from(authority: Authority<'a>) -> Reference<'a>

Converts to this type from the input type.
§

impl<'a> From<Authority<'a>> for Uri<'a>

§

fn from(other: Authority<'a>) -> Uri<'a>

Converts to this type from the input type.
§

impl Hash for Authority<'_>

§

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

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

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

impl IntoOwned for Authority<'_>

§

type Owned = Authority<'static>

The owned version of the type.
§

fn into_owned(self) -> Authority<'static>

Converts self into an owned version of itself.
§

impl PartialEq<&str> for Authority<'_>

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<Authority<'_>> for str

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'b, 'a> PartialEq<Authority<'a>> for Uri<'b>

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a, 'b> PartialEq<Authority<'b>> for Authority<'a>

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'b, 'a> PartialEq<Uri<'b>> for Authority<'a>

§

fn eq(&self, other: &Uri<'b>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<str> for Authority<'_>

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> Serialize for Authority<'a>

§

fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl<'a> TryFrom<&'a String> for Authority<'a>

§

type Error = Error<'a>

The type returned in the event of a conversion error.
§

fn try_from( value: &'a String ) -> Result<Authority<'a>, <Authority<'a> as TryFrom<&'a String>>::Error>

Performs the conversion.
§

impl<'a> TryFrom<&'a str> for Authority<'a>

§

type Error = Error<'a>

The type returned in the event of a conversion error.
§

fn try_from( value: &'a str ) -> Result<Authority<'a>, <Authority<'a> as TryFrom<&'a str>>::Error>

Performs the conversion.
§

impl TryFrom<String> for Authority<'static>

§

type Error = Error<'static>

The type returned in the event of a conversion error.
§

fn try_from( value: String ) -> Result<Authority<'static>, <Authority<'static> as TryFrom<String>>::Error>

Performs the conversion.
§

impl<'a> TryFrom<Uri<'a>> for Authority<'a>

§

type Error = TryFromUriError

The type returned in the event of a conversion error.
§

fn try_from( uri: Uri<'a> ) -> Result<Authority<'a>, <Authority<'a> as TryFrom<Uri<'a>>>::Error>

Performs the conversion.
§

impl Eq for Authority<'_>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Authority<'a>

§

impl<'a> Send for Authority<'a>

§

impl<'a> Sync for Authority<'a>

§

impl<'a> Unpin for Authority<'a>

§

impl<'a> UnwindSafe for Authority<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self>

§

impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

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> IntoCollection<T> for T

§

fn into_collection<A>(self) -> SmallVec<A>where A: Array<Item = T>,

Converts self into a collection.
§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where F: FnMut(T) -> U, A: Array<Item = U>,

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,