[][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.

Methods

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<'_> PartialEq<Username<'_>> for Username<'_>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

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

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

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

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

type Target = str

The resulting type after dereferencing.

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

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

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

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

type Error = InvalidUserInfo

The type returned in the event of a conversion error.

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

type Error = InvalidUserInfo

The type returned in the event of a conversion error.

Auto Trait Implementations

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

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

Blanket Implementations

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

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

type Owned = T

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

The type returned in the event of a conversion error.

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