[−][src]Struct uriparse::authority::RegisteredName
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]
fn clone(&self) -> RegisteredName<'name>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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]
fn from(value: RegisteredName<'name>) -> String
[src]
impl<'_> Hash for RegisteredName<'_>
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
fn eq(&self, other: &RegisteredName<'_>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'name> PartialEq<RegisteredName<'name>> for [u8]
[src]
fn eq(&self, other: &RegisteredName<'name>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'name> PartialEq<RegisteredName<'name>> for &'a [u8]
[src]
fn eq(&self, other: &RegisteredName<'name>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'name> PartialEq<RegisteredName<'name>> for str
[src]
fn eq(&self, other: &RegisteredName<'name>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a, 'name> PartialEq<RegisteredName<'name>> for &'a str
[src]
fn eq(&self, other: &RegisteredName<'name>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[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.
fn try_from(value: &'name [u8]) -> Result<Self, Self::Error>
[src]
impl<'name> TryFrom<&'name str> for RegisteredName<'name>
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> 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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,