home ~ projects ~ socials

Serialize Data Structures With Key Value Pairs In Rust

Add this to enums:

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

TODO

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

-- end of line --

References