Deriving Deserialize on Structs as Arrays

2022-12-16

Was watching Decrusted: Serde and found out when you derive #[serde(Deserialize, Serialize)] it can be to an array as opposed to a mapping of some key:value.

This is especially helpful as I've got some little automations which query Fastmail via jmap which heavily utilizes arrays for defining what query to run.

i.e.

#[derive(serde::Deserialize, serde::Serialize)]
struct RGB {
  r: u64,
  g: u64,
  b: u64
}

can correctly deserialize [12,222,55] into a Rust struct with named fields!