[][src]Struct uriparse::authority::RegisteredName

pub struct RegisteredName<'name> { /* fields omitted */ }

A host that is a registered name (i.e. not an IP literal).

The registered name is case-insensitive meaning that "example.com" and "ExAmPlE.CoM" refer to the same registered name. Furthermore, percent-encoding plays no role in equality checking for characters in the unreserved character set meaning that "example.com" and "ex%61mple.com" are identical. Both of these attributes are reflected in the equality and hash functions.

However, be aware that just because percent-encoding plays no role in equality checking does not mean that the host is normalized. If the registered name needs to be normalized, use the RegisteredName::normalize function.

Implementations

impl<'_> RegisteredName<'_>[src]

pub fn as_borrowed(&self) -> RegisteredName<'_>[src]

Returns a new registered name which is identical but has a lifetime tied to this registered name.

pub fn as_str(&self) -> &str[src]

Returns a str representation of the registered name.

Examples

use std::convert::TryFrom;

use uriparse::RegisteredName;

let name = RegisteredName::try_from("example.com").unwrap();
assert_eq!(name.as_str(), "example.com");

pub fn into_owned(self) -> RegisteredName<'static>[src]

Converts the RegisteredName into an owned copy.

If you construct the registered name 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 registered name will just copy the references, and thus the lifetime will remain the same.

pub fn is_normalized(&self) -> bool[src]

Returns whether the registered name is normalized.

Registered names are considered normalized if all characters are lowercase, no bytes that are in the unreserved character set are percent-encoded, and all alphabetical characters in percent-encodings are uppercase.

This function runs in constant-time.

Examples

use std::convert::TryFrom;

use uriparse::RegisteredName;

let name = RegisteredName::try_from("example.com").unwrap();
assert!(name.is_normalized());

let mut name = RegisteredName::try_from("EXAMPLE.COM").unwrap();
assert!(!name.is_normalized());
name.normalize();
assert!(name.is_normalized());

pub fn normalize(&mut self)[src]

Normalizes the registered name such that all characters are lowercase, no bytes that are in the unreserved character set are percent-encoded, and all alphabetical characters in percent-encodings are uppercase.

If the registered name is already normalized, the function will return immediately. Otherwise, if the registered name is not owned, this function will perform an allocation to clone it. The normalization itself though, is done in-place with no extra memory allocations required.

Examples

use std::convert::TryFrom;

use uriparse::RegisteredName;

let mut name = RegisteredName::try_from("example.com").unwrap();
name.normalize();
assert_eq!(name.to_string(), "example.com");

let mut name = RegisteredName::try_from("%ff%41").unwrap();
assert_eq!(name.to_string(), "%ff%41");
name.normalize();
assert_eq!(name.to_string(), "%FFA");

Trait Implementations

impl<'_> AsRef<[u8]> for RegisteredName<'_>[src]

impl<'_> AsRef<str> for RegisteredName<'_>[src]

impl<'name> Clone for RegisteredName<'name>[src]

impl<'name> Debug for RegisteredName<'name>[src]

impl<'_> Display for RegisteredName<'_>[src]

impl<'_> Eq for RegisteredName<'_>[src]

impl<'name> From<RegisteredName<'name>> for String[src]

impl<'_> Hash for RegisteredName<'_>[src]

impl<'a, '_> PartialEq<&'a [u8]> for RegisteredName<'_>[src]

impl<'a, '_> PartialEq<&'a str> for RegisteredName<'_>[src]

impl<'_> PartialEq<[u8]> for RegisteredName<'_>[src]

impl<'_> PartialEq<RegisteredName<'_>> for RegisteredName<'_>[src]

impl<'name> PartialEq<RegisteredName<'name>> for [u8][src]

impl<'a, 'name> PartialEq<RegisteredName<'name>> for &'a [u8][src]

impl<'name> PartialEq<RegisteredName<'name>> for str[src]

impl<'a, 'name> PartialEq<RegisteredName<'name>> for &'a str[src]

impl<'_> PartialEq<str> for RegisteredName<'_>[src]

impl<'name> TryFrom<&'name [u8]> for RegisteredName<'name>[src]

type Error = RegisteredNameError

The type returned in the event of a conversion error.

impl<'name> TryFrom<&'name str> for RegisteredName<'name>[src]

type Error = RegisteredNameError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'name> RefUnwindSafe for RegisteredName<'name>

impl<'name> Send for RegisteredName<'name>

impl<'name> Sync for RegisteredName<'name>

impl<'name> Unpin for RegisteredName<'name>

impl<'name> UnwindSafe for RegisteredName<'name>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.