[][src]Struct uriparse::authority::Password

pub struct Password<'password> { /* fields omitted */ }

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

Even though this library supports parsing the password from the user information, it should be noted that the format "username:password" is deprecated. Also, be careful logging this!

The password is case-sensitive. Furthermore, percent-encoding plays no role in equality checking for characters in the unreserved character set meaning that "password" and "p%61ssword" 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 password is normalized. If the password needs to be normalized, use the Password::normalize function.

Implementations

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

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

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

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

Returns a str representation of the password.

Examples

use std::convert::TryFrom;

use uriparse::Password;

let password = Password::try_from("password").unwrap();
assert_eq!(password, "password");

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

Converts the Password into an owned copy.

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

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

Returns whether the password is normalized.

A normalized password 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::Password;

let password = Password::try_from("password").unwrap();
assert!(password.is_normalized());

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

pub fn normalize(&mut self)[src]

Normalizes the password 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 password is already normalized, the function will return immediately. Otherwise, if the password 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::Password;

let mut password = Password::try_from("password").unwrap();
password.normalize();
assert_eq!(password, "password");

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

Trait Implementations

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

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

impl<'password> Clone for Password<'password>[src]

impl<'password> Debug for Password<'password>[src]

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

type Target = str

The resulting type after dereferencing.

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

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

impl<'password> From<Password<'password>> for String[src]

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

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

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

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

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

impl<'password> PartialEq<Password<'password>> for [u8][src]

impl<'a, 'password> PartialEq<Password<'password>> for &'a [u8][src]

impl<'password> PartialEq<Password<'password>> for str[src]

impl<'a, 'password> PartialEq<Password<'password>> for &'a str[src]

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

impl<'password> TryFrom<&'password [u8]> for Password<'password>[src]

type Error = PasswordError

The type returned in the event of a conversion error.

impl<'password> TryFrom<&'password str> for Password<'password>[src]

type Error = PasswordError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'password> RefUnwindSafe for Password<'password>

impl<'password> Send for Password<'password>

impl<'password> Sync for Password<'password>

impl<'password> Unpin for Password<'password>

impl<'password> UnwindSafe for Password<'password>

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.