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

Methods

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

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

This method tests for !=.

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

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

This method tests for !=.

impl<'fragment> PartialEq<Fragment<'fragment>> 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 Fragment<'_>[src]

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

This method tests for !=.

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

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

This method tests for !=.

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

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

This method tests for !=.

impl<'fragment> PartialEq<Fragment<'fragment>> 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 Fragment<'_>[src]

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

This method tests for !=.

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

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

This method tests for !=.

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

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

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

Performs copy-assignment from source. Read more

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

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

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

impl<'_> Hash for Fragment<'_>[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<'_> Deref for Fragment<'_>[src]

type Target = str

The resulting type after dereferencing.

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

type Error = InvalidFragment

The type returned in the event of a conversion error.

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

type Error = InvalidFragment

The type returned in the event of a conversion error.

Auto Trait Implementations

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

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

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]