deser-urlencoded
Query strings and form data (application/x-www-form-urlencoded) for
deser.
Everything in a query string is text, only the type a value is deserialized into knows what it means. With serde this information gets lost as soon as values are buffered, which is why numbers stop parsing in flattened structs and in internally tagged and untagged enums. deser passes the text on as lexical atoms which are parsed by the type they end up in, also after buffering:
use ;
let query = "q=rust&limit=10&offset=&tags=a&tags=b";
let search: Search = from_str.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
What works:
- Repeated keys (
a=1&a=2) as sent by<select multiple>, brackets (a[]=1), indexes (a[0][b]=1) and dots (a.b=1). A single value is accepted for sequences, a key given more than once for a single value uses the last value (or the first one or it's an error). - Nested structs, maps and enums.
- Empty values are
Nonefor optionals of types that do not accept them (page=for anOption<u32>). Booleans accept what checkboxes send. - Errors point at the position in the input and (with
deser-path) at the path of the value. - Serializing like
serde_url_params(a=1&a=2), with brackets or indexes.
License and Links
- Issue Tracker
- Documentation
- License: Apache-2.0