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

Error when deserializing untagged variant of enum #354

Open
Scripter17 opened this issue Sep 18, 2024 · 0 comments
Open

Error when deserializing untagged variant of enum #354

Scripter17 opened this issue Sep 18, 2024 · 0 comments

Comments

@Scripter17
Copy link

#148 and #149 address when an entire enum is #[serde(untagged)], but if just a single variant is untagged an error occurs.

The following code works fine for deserializing B but panics when deserializing A.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
enum A {
    #[serde(untagged)]
    A {
        a: u8
    }
}

#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum B {
    C(C)
}

#[derive(Serialize, Deserialize)]
enum C {
    C
}

fn main() {
    let data = rmp_serde::to_vec(&B::C(C::C)).unwrap();
    rmp_serde::from_slice::<B>(&data).unwrap();
    let data = rmp_serde::to_vec(&A::A{a: 2}).unwrap();
    rmp_serde::from_slice::<A>(&data).unwrap();
}
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

1 participant