Skip to content

Rust: Support tagged unions #533

@phrohdoh

Description

@phrohdoh

Currently quicktype always emits serde(untagged) for unions.

Serde supports multiple tagged union forms:

Externally

#[derive(Serialize, Deserialize)]
enum Message {
    Request { id: String, method: String, params: Params },
    Response { id: String, result: Value },
}
{"Request": {"id": "...", "method": "...", "params": {...}}}

Internally

#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
enum Message {
    Request { id: String, method: String, params: Params },
    Response { id: String, result: Value },
}
{"type": "Request", "id": "...", "method": "...", "params": {...}}

Adjacently

#[derive(Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
enum Block {
    Para(Vec<Inline>),
    Str(String),
}
{"t": "Para", "c": [{...}, {...}]}
{"t": "Str", "c": "the string"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    RustRust Output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions