expression
Internally tagged enums
Put the discriminator inside the same object as named variant fields. Tuple variants are not supported by this representation. Serde and serde_json are external crates; use the staged Cargo manifest. Expected stdout (not executed): Update 5 Common mistake: Using an internal tag with tuple variants or colliding field names.
Formal Syntax & Structure
rust syntaxrust
#[serde(tag = "kind")]Working Example
Example Snippetrust
fn main() { #[derive(serde::Serialize)] #[serde(tag = "kind")] enum Event { Update { count: u32 } } let v = serde_json::to_value(Event::Update { count: 5 }).unwrap(); println!("{} {}", v["kind"].as_str().unwrap(), v["count"].as_u64().unwrap());}