Function percent_encoding::percent_encode
[−]
[src]
pub fn percent_encode<E: EncodeSet>(
input: &[u8],
encode_set: E
) -> PercentEncode<E>
Percent-encode the given bytes with the given encode set.
The encode set define which bytes (in addition to non-ASCII and controls)
need to be percent-encoded.
The choice of this set depends on context.
For example, ?
needs to be encoded in an URL path but not in a query string.
The return value is an iterator of &str
slices (so it has a .collect::<String>()
method)
that also implements Display
and Into<Cow<str>>
.
The latter returns Cow::Borrowed
when none of the bytes in input
are in the given encode set.
Examples
use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET}; assert_eq!(percent_encode(b"foo bar?", DEFAULT_ENCODE_SET).to_string(), "foo%20bar%3F");