[][src]Struct uriparse::fragment::Fragment

pub struct Fragment<'fragment> { /* fields omitted */ }

The fragment component as defined in [RFC3986, Section 3.5].

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

Implementations

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

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

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

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

Returns a str representation of the fragment.

Examples

use std::convert::TryFrom;

use uriparse::Fragment;

let fragment = Fragment::try_from("fragment").unwrap();
assert_eq!(fragment.as_str(), "fragment");

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

Converts the Fragment into an owned copy.

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

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

Returns whether the fragment is normalized.

A normalized fragment 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::Fragment;

let fragment = Fragment::try_from("fragment").unwrap();
assert!(fragment.is_normalized());

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

pub fn normalize(&mut self)[src]

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

let mut fragment = Fragment::try_from("fragment").unwrap();
fragment.normalize();
assert_eq!(fragment, "fragment");

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

Trait Implementations

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

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

impl<'fragment> Clone for Fragment<'fragment>[src]

impl<'fragment> Debug for Fragment<'fragment>[src]

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

type Target = str

The resulting type after dereferencing.

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

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

impl<'fragment> From<Fragment<'fragment>> for String[src]

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

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

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

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

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

impl<'fragment> PartialEq<Fragment<'fragment>> for [u8][src]

impl<'a, 'fragment> PartialEq<Fragment<'fragment>> for &'a [u8][src]

impl<'fragment> PartialEq<Fragment<'fragment>> for str[src]

impl<'a, 'fragment> PartialEq<Fragment<'fragment>> for &'a str[src]

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

impl<'fragment> TryFrom<&'fragment [u8]> for Fragment<'fragment>[src]

type Error = FragmentError

The type returned in the event of a conversion error.

impl<'fragment> TryFrom<&'fragment str> for Fragment<'fragment>[src]

type Error = FragmentError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<'fragment> RefUnwindSafe for Fragment<'fragment>

impl<'fragment> Send for Fragment<'fragment>

impl<'fragment> Sync for Fragment<'fragment>

impl<'fragment> Unpin for Fragment<'fragment>

impl<'fragment> UnwindSafe for Fragment<'fragment>

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.