Discussion
Loading...

Post

  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Kat March谩n 馃悎
@zkat@toot.cat  路  activity timestamp 3 months ago

Dear #Rust#RustLang folks doing #Axum

What's your preferred way of having a single handler for multiple form submission types?

That is, let's say I have a settings page, and there's different "sections" to the settings, which all get handled differently, but I want the Form to get deserialized per usual?

Unfortunately, serde_html_form doesn't support deserializing enums for something like this? At least not out of the box?

  • Copy link
  • Flag this post
  • Block
potatomeow
@potatomeow@fosstodon.org replied  路  activity timestamp 3 months ago
@zkat depends on what type of settings that are being changed.

updating all sections in 1 single request sounds to me (im guessing from here onward), you are making sure the request transaction to be ACID, maybe??? even though each section to the settings are backed by different db tables... idk

  • Copy link
  • Flag this comment
  • Block
Natalie
@natkr@hachyderm.io replied  路  activity timestamp 3 months ago
@zkat I haven't tried with serde_html_form, but at least for serde_urlencoded.. (which SHF seems to be a fork of?)

Did you try adding `#[serde(tag = "type")]` to the enum? That way, serde stores the discriminator tag inside of the variant instead of wrapping it, which should work better for "flat" formats like HTML forms.

For example (using axum::Form, which uses serde_urlencoded): https://gist.github.com/nightkr/f07e38a321aae8278ccc1e07bd1bc538

More details: https://serde.rs/enum-representations.html

  • Copy link
  • Flag this comment
  • Block
Natalie
@natkr@hachyderm.io replied  路  activity timestamp 3 months ago
@zkat Side note: does anyone know of a pastebin that doesn't suck? Feels weird that I'm still relying on github for that...
  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About 路 Code of conduct 路 Privacy 路 Users 路 Instances
Bonfire social 路 1.0.0-rc.3.21 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct
Home
Login