percent-encoding 1.0.1

Percent encoding and decoding

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");