x-www-form-urlencoded meets Serde
Clone or download
bors[bot] and smangelsdorf Merge #30
30: Support deserializing a (keyword) string into a unit-only enum r=nox a=smangelsdorf

This adds support for deserializing a structure such as:

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
enum SortOrder {

#[derive(Serialize, Deserialize, Debug)]
struct SearchOptions {
    sort: SortOrder,

This is already supported for serialization (and I've added a test case for the existing support as part of this PR), but attempting to deserialize the string `"sort=asc"` would result in the error:

invalid type: string "asc", expected enum SortOrder

I've made a sample in the playground of the way this is handled in `serde_urlencoded` vs `serde_json`: https://play.rust-lang.org/?gist=75fc1e5bbbc1eec29a472373d47488a0&version=stable

This brings the behaviour in line with the way `serde_json` currently handles this case, which I hope is appropriate. Happy to tweak the behaviour if there's a better way to handle it.

Co-authored-by: Shaun Mangelsdorf <s.mangelsdorf@gmail.com>
Latest commit 199ed02 Aug 14, 2018


x-www-form-urlencoded meets Serde

This crate is a Rust library for serialising to and deserialising from the application/x-www-form-urlencoded format. It is built upon Serde, a high performance generic serialization framework and rust-url, a URL parser for Rust.


This crate works with Cargo and can be found on crates.io with a Cargo.toml like:

serde_urlencoded = "0.5.1"

Getting help

Serde developers live in the #serde channel on irc.mozilla.org and most rust-url developers live in the #servo one. The #rust channel is also a good resource with generally faster response time but less specific knowledge about Serde, rust-url or this crate. If IRC is not your thing, we are happy to respond to GitHub issues as well.


serde_urlencoded is licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in serde_urlencoded by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.