[][src]Struct pct_str::PctStr

pub struct PctStr { /* fields omitted */ }

Percent-Encoded string slice.

This is the equivalent of str for percent-encoded strings. This is an unsized type, meaning that it must always be used behind a pointer like & or Box. For an owned version of this type, see PctString.

Examples

use pct_str::PctStr;

let buffer = "Hello%20World%21";
let pct_str = PctStr::new(buffer).unwrap();

// You can compare percent-encoded strings with a regular string.
assert!(pct_str == "Hello World!");

// The underlying string is unchanged.
assert!(pct_str.as_str() == "Hello%20World%21");

// Just as a regular string, you can iterate over the
// encoded characters of `pct_str` with [`PctStr::chars`].
for c in pct_str.chars() {
	print!("{}", c);
}

// You can decode the string and every remove percent-encoded characters
// with the [`PctStr::decode`] method.
let decoded_string: String = pct_str.decode();
println!("{}", decoded_string);

Implementations

impl PctStr[src]

pub fn new<S: AsRef<str> + ?Sized>(str: &S) -> Result<&PctStr>[src]

Create a new percent-encoded string slice.

The input slice is checked for correct percent-encoding. If the test fails, a InvalidEncoding error is returned.

pub unsafe fn new_unchecked<S: AsRef<str> + ?Sized>(str: &S) -> &PctStr[src]

Create a new percent-encoded string slice without checking for correct encoding.

This is an unsafe function. The resulting string slice will have an undefined behaviour if the input slice is not percent-encoded.

pub fn len(&self) -> usize[src]

Length of the string slice, in bytes.

Note that two percent-encoded strings with different lengths may represent the same string.

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

Get the underlying percent-encoded string slice.

pub fn chars(&self) -> Chars<'_>

Notable traits for Chars<'a>

impl<'a> Iterator for Chars<'a> type Item = char;
[src]

Iterate over the encoded characters of the string.

pub fn decode(&self) -> String[src]

Decoding.

Return the string with the percent-encoded characters decoded.

Trait Implementations

impl Debug for PctStr[src]

impl Display for PctStr[src]

impl Eq for PctStr[src]

impl Hash for PctStr[src]

impl Ord for PctStr[src]

impl PartialEq<PctStr> for PctStr[src]

impl PartialEq<PctStr> for PctString[src]

impl PartialEq<PctString> for PctStr[src]

impl PartialEq<str> for PctStr[src]

impl PartialOrd<PctStr> for PctStr[src]

impl PartialOrd<PctStr> for PctString[src]

impl PartialOrd<PctString> for PctStr[src]

Auto Trait Implementations

impl RefUnwindSafe for PctStr

impl Send for PctStr

impl Sync for PctStr

impl Unpin for PctStr

impl UnwindSafe for PctStr

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> ToString for T where
    T: Display + ?Sized
[src]