Skip to content

Support for discriminated form? #1221

Answered by davidpdrsn
yatesco asked this question in Q&A
Discussion options

You must be logged in to vote

Almost. This should work

#[derive(Deserialize, Debug)]
#[serde(tag = "action", rename_all = "kebab-case")]
enum Input {
    Rename { rename: String },
    Delete,
    SomethingElse { foo: String, bar: usize },
}

Although you'll have to POST the data as action=rename&rename=foobar.

There might be some serde attributes that you can use to get exactly what you wrote but I'm not sure.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yatesco
Comment options

Answer selected by yatesco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants