Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with untagged enum #66

Open
hronro opened this issue Mar 6, 2020 · 3 comments
Open

Doesn't work with untagged enum #66

hronro opened this issue Mar 6, 2020 · 3 comments

Comments

@hronro
Copy link

hronro commented Mar 6, 2020

It works when all the fields in the enum are String, but failed in other cases.

use serde::Deserialize; // 1.0.104
use serde_urlencoded; // 0.6.1

#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum Q1 {
    A { foo: String },
    B { bar: String },
}

#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum Q2 {
    A { foo: String },
    B { bar: i32 },
}

fn main() {
    let q1 = "bar=123";
    let q1s = serde_urlencoded::from_str::<Q1>(q1).unwrap();
    println!("q1: {:#?}", q1s);

    let q2 = "bar=123";
    let q2s = serde_urlencoded::from_str::<Q2>(q2).unwrap();
    println!("q2: {:#?}", q2s);
}

playground

@nox
Copy link
Owner

nox commented Mar 6, 2020

Patches welcome!

@davepacheco
Copy link

davepacheco commented Aug 3, 2020

By chance, has anybody taken a look at why this doesn't work (e.g., is it somehow behaving correctly vs minor bug vs deeper design issue)?

@davepacheco
Copy link

This seems to be caused by serde-rs/serde#1183. It's similar to #33.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants