json
json copied to clipboard
How to define i32 tags in enum?
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
}
This feature needs to be implemented in serde, not serde-json: https://github.com/serde-rs/serde/pull/2056. We just need to pray dtolnay finds the time someday to click the merge button on that very useful PR