[][src]Struct uriparse::authority::Username

pub struct Username<'username> { /* fields omitted */ }

The username component of the authority as defined in [RFC3986, Section 3.2.1].

The username is case-sensitive. Furthermore, percent-encoding plays no role in equality checking for characters in the unreserved character set meaning that "username" and "usern%61me" are identical. Both of these attributes are reflected in the equality and hash functions.

Be aware that just because percent-encoding plays no role in equality checking does not mean that the username is normalized. If the username needs to be normalized, use the Username::normalize function.

Implementations

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

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

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

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

Returns a str representation of the username.

Examples

use std::convert::TryFrom;

use uriparse::Username;

let username = Username::try_from("username").unwrap();
assert_eq!(username.as_str(), "username");

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

Converts the Username into an owned copy.

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

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

Returns whether the username is normalized.

A normalized username will have no bytes that are in the unreserved character set percent-encoded and all alphabetical characters in percent-encodings will be uppercase.

This function runs in constant-time.

Examples

use std::convert::TryFrom;

use uriparse::Username;

let username = Username::try_from("username").unwrap();
assert!(username.is_normalized());

let mut username = Username::try_from("%ff%ff").unwrap();
assert!(!username.is_normalized());
username.normalize();
assert!(username.is_normalized());

pub fn normalize(&mut self)[src]

Normalizes the username such that it will have no bytes that are in the unreserved character set percent-encoded and all alphabetical characters in percent-encodings will be uppercase.

If the username is already normalized, the function will return immediately. Otherwise, if the username 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::Username;

let mut username = Username::try_from("username").unwrap();
username.normalize();
assert_eq!(username, "username");

let mut username = Username::try_from("%ff%41").unwrap();
assert_eq!(username, "%ff%41");
username.normalize();
assert_eq!(username, "%FFA");

Trait Implementations

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

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

impl<'username> Clone for Username<'username>[src]

impl<'username> Debug for Username<'username>[src]

impl<'_> Deref for Username<'_>[src]

type Target = str

The resulting type after dereferencing.

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

impl<'username> Eq for Username<'username>[src]

impl<'username> From<Username<'username>> for String[src]

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

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

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

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

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

impl<'username> PartialEq<Username<'username>> for [u8][src]

impl<'a, 'username> PartialEq<Username<'username>> for &'a [u8][src]

impl<'username> PartialEq<Username<'username>> for str[src]

impl<'a, 'username> PartialEq<Username<'username>> for &'a str[src]

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

impl<'username> TryFrom<&'username [u8]> for Username<'username>[src]

type Error = UsernameError

The type returned in the event of a conversion error.

impl<'username> TryFrom<&'username str> for Username<'username>[src]

type Error = UsernameError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'username> RefUnwindSafe for Username<'username>

impl<'username> Send for Username<'username>

impl<'username> Sync for Username<'username>

impl<'username> Unpin for Username<'username>

impl<'username> UnwindSafe for Username<'username>

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.