Function percent_encoding::percent_encode

source ·
pub fn percent_encode<'a>(
    input: &'a [u8],
    ascii_set: &'static AsciiSet,
) -> PercentEncode<'a> 
Expand description

Percent-encode the given bytes with the given set.

Non-ASCII bytes and bytes in ascii_set are encoded.

The return type:

  • Implements Iterator<Item = &str> and therefore has a .collect::<String>() method,
  • Implements Display and therefore has a .to_string() method,
  • Implements Into<Cow<str>> borrowing input when none of its bytes are encoded.

§Examples

use percent_encoding::{percent_encode, NON_ALPHANUMERIC};

assert_eq!(percent_encode(b"foo bar?", NON_ALPHANUMERIC).to_string(), "foo%20bar%3F");