Support for discriminated form? #1221
-
I'm expecting the answer is no, and I understand why, but on the off chance ;-).... I have a front end which posts to an I'm talking about something like: enum MyForm {
Rename(String),
Delete.
SomethingElse(String, usize)
} with POSTS like I think I'm going to end up JSONing it on the front end but I'm using the excellent https://htmx.org so would prefer to avoid that if possible. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 There might be some serde attributes that you can use to get exactly what you wrote but I'm not sure. |
Beta Was this translation helpful? Give feedback.
Almost. This should work
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.