Crate percent_encoding
source ·Expand description
URLs use special chacters to indicate the parts of the request. For example, a forward slash indicates a path. In order for that charcter to exist outside of a path separator, that charcter would need to be encoded.
Percent encoding replaces reserved charcters with the %
escape charcter followed by hexidecimal
ASCII representaton. For non-ASCII charcters that are percent encoded, a UTF-8 byte sequence
becomes percent encoded. A simple example can be seen when the space literal is replaced with
%20
.
Percent encoding is further complicated by the fact that different parts of an URL have
different encoding requirements. In order to support the variety of encoding requirements,
url::percent_encoding
includes different encode sets.
See URL Standard for details.
This module provides some *_ENCODE_SET
constants.
If a different set is required, it can be created with
the define_encode_set!
macro.
Examples
use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
assert_eq!(utf8_percent_encode("foo bar?", DEFAULT_ENCODE_SET).to_string(), "foo%20bar%3F");
Macros
- Define a new struct that implements the
EncodeSet
trait, for use inpercent_decode()
and related functions.
Structs
- This encode set is used for path components.
- This encode set is used for on ‘/’-separated path segment
- The return type of
percent_decode()
. - The return type of
percent_encode()
andutf8_percent_encode()
. - This encode set is used in the URL parser for query strings.
- This encode set is used for the path of cannot-be-a-base URLs.
- This encode set is used for username and password.
Traits
- Represents a set of characters / bytes that should be percent-encoded.
Functions
- Percent-decode the given bytes.
- Percent-encode the given bytes with the given encode set.
- Return the percent-encoding of the given bytes.
- Percent-encode the UTF-8 encoding of the given string.