serde-mappable-seq
An unofficial third-party crate to deserialize sequences of keyed structs into HashMaps or BTreeMaps and vice versa.
Sometimes APIs will provide a list of instances of a resource in a sequence, such as a list of users. Imagine this JSON payload:
If you want to get something by ID, you're going to either need to post-process it manually (slightly annoying) or loop through to find the user with the ID (slightly costly).
serde-mappable-seq makes turning a sequence of a resource into a keyed
map easy.
Installation
This library requires at least Rust 1.31.0.
Add this to your Cargo.toml:
[]
= "0.1"
Examples
Deserialize a struct containing a sequence of 2 users into a HashMap, keyed by their IDs:
use ;
use Key;
use HashMap;
#
Serializing the instance of the response struct in the above example will net back the original input.
License
ISC.