Crate percent_encoding[][src]

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 in percent_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

PercentDecode

The return type of percent_decode().

PercentEncode

The return type of percent_encode() and utf8_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

EncodeSet

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.