[−][src]Struct pct_str::PctStr
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<'_>ⓘ
[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]
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,