Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Serialize Data Structures With Key Value Pairs In Rust

Add this to enums:

Code

use serde::Serialize;

#[derive(Debug, PartialEq, Serialize)]
#[serde(tag = "type", content = "content", rename_all = "lowercase")]
pub enum Widget {
  Alfa,
  Bravo
}

That will display the type for each element so you can access them by key in (for example) minijinja

  • talk about the different parts there and the derive stuff that helps with the basic usage

References