You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive(serde::Deserialize)]pubstructForm{value:Vec<String>,}#[derive(serde::Deserialize)]#[serde(untagged)]pubenumEnumForm{Form(Form),}fnmain(){// Workslet _:Form = serde_html_form::from_str("value=&value=abc").unwrap();// Error("data did not match any variant of untagged enum EnumForm")let _:EnumForm = serde_html_form::from_str("value=&value=abc").unwrap();}
The text was updated successfully, but these errors were encountered:
This is an instance of serde-rs/serde#1183, just like #18. There's nothing this library can do about it.
What you can do is write a Deserialize impl like this instead of relying on #[serde(untagged)]:
use serde::de::{Deserialize,Deserializer,Erroras _};impl<'de>Deserialize<'de>forEnumForm{fndeserialize<D>(deserializer:D) -> Result<Self,D::Error>whereD:Deserializer<'de>,{#[derive(Deserialize)]structFormStructRepr{#[serde(default)]mutually_exclusive_field_a:Vec<String>,mutually_exclusive_field_b:Option<u16>,}let s = FormStructRepr::deserialize(deserializer)?;match(s.mutually_exclusive_field_a.is_empty(), s.mutually_exclusive_field_b){(false,None) => Ok(Self::FormA{value: s.mutually_exclusive_field_a,}),(true,Some(b_value)) => Ok(Self::FormB{value: b_value }),(false,Some(_)) => Err(D::Error::custom("only one of mutually_exclusive_field_a, mutually_exclusive_field_b may be set",)),(true,None) => Err(D::Error::custom("one of mutually_exclusive_field_a, mutually_exclusive_field_b must be set",)),}}}
The text was updated successfully, but these errors were encountered: