# [−][src]Function percent_encoding::percent_encode

ⓘImportant traits for PercentEncode<'a, E>

### Important traits for PercentEncode<'a, E>

`impl<'a, E: EncodeSet> Iterator for PercentEncode<'a, E> type Item = &'a str;`

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

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)