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_
encode_ set - Define a new struct
that implements the
EncodeSet
trait, for use inpercent_decode()
and related functions.
Structs§
- DEFAULT_
ENCODE_ SET - This encode set is used for path components.
- PATH_
SEGMENT_ ENCODE_ SET - This encode set is used for on ‘/’-separated path segment
- Percent
Decode - The return type of
percent_decode()
. - Percent
Encode - The return type of
percent_encode()
andutf8_percent_encode()
. - QUERY_
ENCODE_ SET - This encode set is used in the URL parser for query strings.
- SIMPLE_
ENCODE_ SET - This encode set is used for the path of cannot-be-a-base URLs.
- USERINFO_
ENCODE_ SET - This encode set is used for username and password.
Traits§
- Encode
Set - Represents a set of characters / bytes that should be percent-encoded.
Functions§
- percent_
decode - Percent-decode the given bytes.
- percent_
encode - Percent-encode the given bytes with the given encode set.
- percent_
encode_ byte - Return the percent-encoding of the given bytes.
- utf8_
percent_ encode - Percent-encode the UTF-8 encoding of the given string.