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

How to define i32 tags in enum? #1016

Open
lz1998 opened this issue Apr 23, 2023 · 1 comment
Open

How to define i32 tags in enum? #1016

lz1998 opened this issue Apr 23, 2023 · 1 comment

Comments

@lz1998
Copy link

lz1998 commented Apr 23, 2023

https://serde.rs/enum-representations.html#internally-tagged

{
    "messages": [
        {"msg_type":1, "a":"aaa"},
        {"msg_type":2, "b":"bbb"},
    ]
}
pub enum Message {
    A(A), // msg_type=1
    B(B)  // msg_type=2
}
pub struct A {
    pub a: String
}
pub struct B {
    pub a: String
}
@kangalio
Copy link

This feature needs to be implemented in serde, not serde-json: serde-rs/serde#2056. We just need to pray dtolnay finds the time someday to click the merge button on that very useful PR

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

No branches or pull requests

2 participants